Skip to content

Conversation

ClintonSarkar
Copy link

@ClintonSarkar ClintonSarkar commented Apr 25, 2024

Added two new methods that read and write strings between godot and socket.

@Abdera7mane
Copy link
Owner

Godot already has StreamPeer::get_string() & StreamPeer::put_string() to read/write a Godot string which is not really useful unless both server and client are Godot applications, so I understand the purpose of the patch you introduced. However StreamPeerUnix::read() & StreamPeerUnix::write() can be replicated in GDScript:

var stream = ... # instantiate and connect to a UNIX socket

# reading
var length = stream.get_available_bytes()
var buffer = stream.get_data(length)[1] as PackedByteArray # the first element contains an error code
var message = buffer.get_string_from_utf8()

# writing
stream.put_data(message.to_utf8_buffer())

further more, this approach is not restricted dealing with UTF8, you are free to store the string in ASCII, UTF16, UTF32 etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants