part 2 - communication

master
chimchooree 2 years ago
parent 95dba37181
commit bea0dd872d

@ -19,6 +19,8 @@ func _ready():
func _connected(id, protocol): func _connected(id, protocol):
print_debug("Client %d connected with protocol: %s" print_debug("Client %d connected with protocol: %s"
% [id, protocol]) % [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): func _close_request(id, code, reason):
print_debug("Client %d disconnecting with code: %d, reason: %s" print_debug("Client %d disconnecting with code: %d, reason: %s"
@ -29,7 +31,15 @@ func _disconnected(id, was_clean = false):
% [id, str(was_clean)]) % [id, str(was_clean)])
func _on_data_received(id): 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): func _process(_delta):
_server.poll() _server.poll()

Loading…
Cancel
Save