Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Punpun | |
Old Version | Published before Godot 3 was released. |
Hey guys, lately I’ve been getting my godot project to work with my old server, and I got it to recieve, process and send data. For sending data I’ve been relying on RawArrays in which I put the string I want to send followed by .to_utf8
. Works well.
However, I need to send more types of data other than strings and single byte integers, like a signed 32bit integer, which I couldn’t find any kind of support in the docs.
I know about .put_32
function in the StreamPeer, but that is only useful when sending one type of information per packet, which is not a common situation.
Is there a alternative to convert data in other encodings? I’m looking for an int.to_s32
(signed 32bits) that would return a RawArray, much like string.to_utf8
does.
Is something like that already in the engine? Should I make a request?
I still don’t understand why you don’t use put_32. This function actually appends one 32-bit integer to the stream, you can continue writing what you want after that. What is wrong with it?
Zylann | 2016-10-27 19:07
Because I as said, put_32
takes all the data, converts it all into this format, and instantly sends it to the server. I work with a RawArray of information, containing various strings and 1byte integers, which don’t use the same encoding as 32bit , if I would send it all in the .put_32
, it would convert all the data as 32bites and it would be unreadable in the server.
Besides, if .to_utf8
exists, functions like .to_16
and .to_s32
also should, they’re all essential for netcode.
Punpun | 2016-10-27 19:31
Which type of StreamPeer are you using? TCP? UDP? Other? (or you don’t know? Sorry I never used this class yet, it just looks confusing because I don’t understand why putting a single integer would send an entire packet :s)
Zylann | 2016-10-27 23:15
I use TCP.
Putting a single integer will send that only integer, but I don’t use it like that, is just not efficient nor is it enough for a consistent replication in most cases. The way I would send a coord. packet, for example, would be: [“coord”.to_utf8
, pos_x, pos_y] (in RawArray)
As you can see, it will send a packet with more than one information and type. The first is a string, my server uses it to know what kind of handling it will need to do; pos_x and pos_y should be written in 32bits, thats why I miss an .to_32
function that works like.to_utf8
.
Punpun | 2016-10-28 00:35