+1 vote

I'm working on a multiplayer game in which the clients will connect to a Python server. I'm after connecting to the server with

var connection = StreamPeerTCP.new()
var wrapped_client = PacketPeerStream.new()
connection.connect_to_host( ip, port )
wrapped_client.set_stream_peer(connection)

And then sending data with

wrapped_client.put_var("hi")

However, the python server receives

         hi

As you can see, there is a prefix that seems to be null data. The hex representation of the data received on the server is as follows,

0c 20 20 20 04 20 20 20 02 20 20 20 68 69

This shows that there is a lot of excess data up until the last two bytes, which represent the characters "h" and "i". What exactly is this data for? Is there any way to not send this excess information?

asked May 29, 2018 in Engine by AngelOnFira (27 points)

1 Answer

+1 vote

https://github.com/godotengine/godot/blob/e7cf2b2e77a097a026f883f003ad299b5d451885/core/io/packet_peer.cpp#L93

http://docs.godotengine.org/en/3.0/tutorials/misc/binary_serialization_api.html

when you send a string down the network api, you are actually sending a variant.

according to the docs, the first 12 bytes are the header for the string.

answered Jul 19, 2018 by hungrymonkey (419 points)
edited Jul 19, 2018 by Calinou
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 How to use this Q&A? before posting your first questions.