From 2a890c7f8a77ee291300f233c1390d9520a091e0 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 22 Sep 2020 18:53:50 +0200 Subject: [PATCH] Fix TCPServer node, by reading -1 bytes --- main.tscn | 9 ++++----- scripts/net-test | 3 ++- tcp_server.gd | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main.tscn b/main.tscn index 5538069..4eb7c7e 100644 --- a/main.tscn +++ b/main.tscn @@ -193,7 +193,6 @@ size_flags_vertical = 3 repository_path = NodePath("../../Repositories/ActiveRepository") [node name="Test" type="Node2D" parent="."] -visible = false script = ExtResource( 9 ) [node name="TCPServer" type="Node" parent="Test"] @@ -201,10 +200,10 @@ script = ExtResource( 8 ) port = 6666 [node name="LineEdit" type="LineEdit" parent="Test"] -margin_left = 1362.49 -margin_top = 827.517 -margin_right = 1772.49 -margin_bottom = 914.517 +margin_left = 720.526 +margin_top = 691.052 +margin_right = 1130.53 +margin_bottom = 778.052 caret_blink = true __meta__ = { "_edit_use_anchors_": false diff --git a/scripts/net-test b/scripts/net-test index 9efeb7b..0f0c7f7 100755 --- a/scripts/net-test +++ b/scripts/net-test @@ -9,7 +9,8 @@ $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", $s = "Hey äöü!"; -$socket->send(chr(length($s))); +my $send_length = pack("L", length($s)); +$socket->send($send_length); $socket->send($s); while(true) { diff --git a/tcp_server.gd b/tcp_server.gd index 98bfb25..286656d 100644 --- a/tcp_server.gd +++ b/tcp_server.gd @@ -17,6 +17,7 @@ func start(): func _process(_delta): if _s.is_connection_available(): if _connected: + _c.disconnect_from_host() push_error("Dropping active connection") _c = _s.take_connection() _connected = true @@ -28,7 +29,7 @@ func _process(_delta): print("disconnected") var available = _c.get_available_bytes() while available > 0: - var data = _c.get_utf8_string(available) + var data = _c.get_utf8_string(-1) emit_signal("data_received", data) available = _c.get_available_bytes()