Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot bind update #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

None yet

2 participants