Websockets _client.get_peer(1).put_packet("Text".to_utf8()) sent as Binary and not Text Frame?

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

So I am not too sure about this, but I have a websocket Ktor Kotlin server, which receives frames. So I’ve tested sending a frame to the Godot Client and I successfully receive it, but whenever I send a packet with

 _client.get_peer(1).put_packet("Test packet".to_utf8()) 

It is received as Binary Fin = true , buffer = 11
Shouldn’t it be a Text Frame?

:bust_in_silhouette: Reply From: Firty
func send_dados(a:int,b:int):
	var temp:Array = [a,b]
	var t0 = var2bytes(temp)
	var t1 = t0.compress(3)
	Client.get_peer(1).put_packet(t1)

func Dados(id):
	var t = Servidor.get_peer(id).get_packet()
	var dados_temp = t.decompress(32000000,3)
	var temp = bytes2var(dados_temp)

with these two functions I can send anything inside this temp array.
in the send_dados function I am using two int, the first to identify the reason for that package, and the second can be anything.

I use compression because in one of my projects I have to send images inside the package, and the limits of the websocket are a bit narrow. otherwise, just:

func send_dados(a:int,b:int):
 var temp:Array = [a,b]
 Client.get_peer(1).put_var(temp)

Server:

func Dados(id):
    var t = Servidor.get_peer(id).get_var()

Due to standard websocket limitations, I also use this in _ready:

Servidor.set_buffers(1024,32,1024,32)

Obs: Servidor is one WebSocketServer (var Servidor = WebSocketServer.new())

Firty | 2020-12-23 20:30

:bust_in_silhouette: Reply From: burdock

It looks like the default write mode for the peer is Binary.

You can change this with:

_client.get_peer(1).set_write_mode(WebSocketPeer.WRITE_MODE_TEXT)

This answer is gold!!!

GForce Productions | 2021-07-31 21:15