0 votes

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):

https://github.com/Kermer/Godot/wiki/tut_data%20transfer#client

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?

in Engine by (311 points)

1 Answer

+1 vote
Best answer

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.

by (311 points)

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.

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.