[gd_scene load_steps=3 format=3 uid="uid://cvfeet1dqmpoe"] [ext_resource type="PackedScene" uid="uid://cdt4rn31xeo85" path="res://microserver.tscn" id="1_0r1oj"] [sub_resource type="GDScript" id="GDScript_loein"] script/source = "extends Node @export var server_path:NodePath var server var service_id_1:int var service_id_2:int const ECHO_FREQ:int = 4 var echo:Thread func _ready(): server = get_node(server_path) service_id_1 = server.add_service(callback_1) service_id_2 = server.add_service(callback_2) echo = Thread.new() echo.start(func(): while server != null: server.send_message(service_id_2, '') OS.delay_msec(ECHO_FREQ) ) func _exit_tree(): server.remove_service(callback_1) server.remove_service(callback_2) server = null echo.wait_to_finish() echo = null func callback_1(message): print('message received {0} by [thread: {1}]'.format([message, OS.get_thread_caller_id()])) var callback_2_counter:int var callback_2_tick:int = Time.get_ticks_msec() func callback_2(_message): const COUNT:int = 250 callback_2_counter += 1 if callback_2_counter >= COUNT: callback_2_counter = 0 print('processed {0} messages cost {1} ms (design: {2} ms)'.format([COUNT, Time.get_ticks_msec() - callback_2_tick, ECHO_FREQ * COUNT])) callback_2_tick = Time.get_ticks_msec() func _on_button_button_up(): var message = 'click at {0} [thread: {1}]'.format([Time.get_time_string_from_system(), OS.get_thread_caller_id()]) server.send_message(service_id_1, message) func _on_timer_timeout(): var message = 'timer triggerd at {0} [thread: {1}]'.format([Time.get_time_string_from_system(), OS.get_thread_caller_id()]) server.send_message(service_id_1, message) " [node name="test" type="Node"] [node name="microserver" parent="." instance=ExtResource("1_0r1oj")] [node name="sub1" type="Node" parent="."] script = SubResource("GDScript_loein") server_path = NodePath("../microserver") [node name="Button" type="Button" parent="sub1"] offset_right = 8.0 offset_bottom = 8.0 text = "Send Message !" [node name="Timer" type="Timer" parent="sub1"] autostart = true [connection signal="button_up" from="sub1/Button" to="sub1" method="_on_button_button_up"] [connection signal="timeout" from="sub1/Timer" to="sub1" method="_on_timer_timeout"]