From bea0dd872d6a7aa7e6fd941f16f20d5a89d5e676 Mon Sep 17 00:00:00 2001 From: chimchooree Date: Sat, 25 Feb 2023 18:53:44 -0600 Subject: [PATCH] part 2 - communication --- Server.gd | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Server.gd b/Server.gd index b2813c8..6fdec94 100644 --- a/Server.gd +++ b/Server.gd @@ -19,6 +19,8 @@ func _ready(): func _connected(id, protocol): print_debug("Client %d connected with protocol: %s" % [id, protocol]) + _server.get_peer(id).put_packet(JSON.print( + {'type': 'test', 'message': "test packet from server"}).to_utf8()) func _close_request(id, code, reason): print_debug("Client %d disconnecting with code: %d, reason: %s" @@ -29,7 +31,15 @@ func _disconnected(id, was_clean = false): % [id, str(was_clean)]) func _on_data_received(id): - pass + + var original = _server.get_peer(id).get_packet().get_string_from_utf8() + var json = JSON.parse(original) + var packet = json.result + if typeof(packet) != 18: + push_error("%s is not a dictionary" % [packet]) + get_tree().quit() + + print_debug("Got data from client %d: %s" % [id, packet]) func _process(_delta): _server.poll()