get_available_packet_count() always returning 0

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

Hey everyone!

I set up a basic TCP server using nodejs. I can connect to it fine from godot, and send messages to it. But, the problem occurs when trying to receive messages sent from nodejs, get_available_packet_count() is always returning 0.

I checked to make sure my tcp was sending data correctly with another tcp client and it was. Godot isn’t receiving it. It’s a simple string of “Hello”

I’m Following this guide: (Clientside part):

I’ve tried to send a buffer from the tcp server, but it’s still not detecting anything. In the source code it’s needing some type of special Variant type. Anyone know how to craft this type of packet outside of Godot?

:bust_in_silhouette: Reply From: wombatTurkey

Alrighty, so I found this solution :DDDDDDDDDDDDD:

Instead of using PacketPeer to get server data, I need to use StreamPeer

And, I need to use get_available_bytes() and get_string() like so:

if client.is_connected() && client.get_available_bytes() >0:
		debug.print_debug("Received: "+str(client.get_string(client.get_available_bytes())))

And it works!

I’m just not sure if this is the correct way feel free to update my answer, but it is working correctly now.

If you check the class documentation you will find that PacketPeer is meant to be used for packet based protocols, i.e. UDP. PacketPeerStream is an exception, but it seems to be using a proprietary protocol on top of TCP. So yeah, it makes sense that you need to use StreamPeer.

Warlaan | 2016-05-29 13:43

Isn’t TCP a packet based protocol though? I think that’s where I got confused, lol no idea.

wombatTurkey | 2016-05-29 14:13

wombatTurkey I had the same problem a c# application client and a godot server I followed the same tutorial and your solution worked for me

reguig | 2017-09-04 13:17