How to send data(string) as websocket server on godot script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kakcalu13

I used the example almost exact same as this minimal server:

but I noticed that there is almost no available how to show to send data as server data.When there was one, it’s usually written on C# which I’m not familiar with.

I write on Godot script mostly.

So, what is the command to send data as server?

I’m currently using python websocket to work with godot script. Both will use server/client. I just don’t know how to send data as server using Websocket.

Keep that in mind, I’m still learning how to use websocket so please feel free to talk to me like as if I’m 5 years old lol

:bust_in_silhouette: Reply From: moser4035

Hi, I think your problem is maybe solved already, but for future readers.

To send data from the server you can use put_packet (PoolByteArray buffer)


or put_var (Variant var, bool full_objects)


This is the code I’m using for sending an UTF-8 string

var packet: PoolByteArray = JSON.print(message).to_utf8()
print("Sending packet ", packet.get_string_from_utf8())