Fix TCPServer node, by reading -1 bytes

This commit is contained in:
Sebastian Morr 2020-09-22 18:53:50 +02:00
parent f0f50bc9fb
commit 2a890c7f8a
3 changed files with 8 additions and 7 deletions

View file

@ -193,7 +193,6 @@ size_flags_vertical = 3
repository_path = NodePath("../../Repositories/ActiveRepository") repository_path = NodePath("../../Repositories/ActiveRepository")
[node name="Test" type="Node2D" parent="."] [node name="Test" type="Node2D" parent="."]
visible = false
script = ExtResource( 9 ) script = ExtResource( 9 )
[node name="TCPServer" type="Node" parent="Test"] [node name="TCPServer" type="Node" parent="Test"]
@ -201,10 +200,10 @@ script = ExtResource( 8 )
port = 6666 port = 6666
[node name="LineEdit" type="LineEdit" parent="Test"] [node name="LineEdit" type="LineEdit" parent="Test"]
margin_left = 1362.49 margin_left = 720.526
margin_top = 827.517 margin_top = 691.052
margin_right = 1772.49 margin_right = 1130.53
margin_bottom = 914.517 margin_bottom = 778.052
caret_blink = true caret_blink = true
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false

View file

@ -9,7 +9,8 @@ $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
$s = "Hey äöü!"; $s = "Hey äöü!";
$socket->send(chr(length($s))); my $send_length = pack("L", length($s));
$socket->send($send_length);
$socket->send($s); $socket->send($s);
while(true) { while(true) {

View file

@ -17,6 +17,7 @@ func start():
func _process(_delta): func _process(_delta):
if _s.is_connection_available(): if _s.is_connection_available():
if _connected: if _connected:
_c.disconnect_from_host()
push_error("Dropping active connection") push_error("Dropping active connection")
_c = _s.take_connection() _c = _s.take_connection()
_connected = true _connected = true
@ -28,7 +29,7 @@ func _process(_delta):
print("disconnected") print("disconnected")
var available = _c.get_available_bytes() var available = _c.get_available_bytes()
while available > 0: while available > 0:
var data = _c.get_utf8_string(available) var data = _c.get_utf8_string(-1)
emit_signal("data_received", data) emit_signal("data_received", data)
available = _c.get_available_bytes() available = _c.get_available_bytes()