this post was submitted on 19 Mar 2024
14 points (100.0% liked)

Godot

5888 readers
42 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

[email protected]

Credits

founded 1 year ago
MODERATORS
 

Godot web socket client is not receiving anymore updates from Revolt web socket server (https://developers.revolt.chat/stack/bonfire/establishing) after first data is received

first data is an Authentication success message:

{
  "type": "Authenticated"
}

This success message comes when a successful token is received.

Since there are no updates and you cannot send any data after initial connection (data_received never called again, so put_packet() not working apparently), the token will have to be in query parameters:

wss://ws.revolt.chat/?version=1&format=json&token={token}

in order to even receive that success message.

An issue relating to web sockets was opened: https://github.com/godotengine/godot/issues/27560

The user claims that one of the headers causes the connection to cease.

The problem header is Connection: close, Upgrade

    GET / HTTP/1.1
    Pragma: no-cache
    Cache-Control: no-cache
    Host: echo.websocket.org
    Upgrade: websocket
    Connection: close, Upgrade
    Sec-WebSocket-Key: HKWU1xOVV6PP6HXjcIWMDQ==
    Sec-WebSocket-Version: 13

    HTTP/1.1 101 Web Socket Protocol Handshake
    Connection: Upgrade
    Date: Sun, 31 Mar 2019 19:09:01 GMT
    Sec-WebSocket-Accept: 0IHc3riAKJz52YmkLVcWrDHvaYs=
    Server: Kaazing Gateway
    Upgrade: websocket

IMPORTANT!!

What SHOULD happen and what happens on other clients like websocketking, piehost, or this one is receiving a READY update

the big issue:

connect_to_url() is the only thing that sends data or the connection closes or a protocol error

It would be of great help if anyone could give any little piece of knowledge or suggestion on this. code

top 2 comments
sorted by: hot top controversial new old
[โ€“] MarshReaper 3 points 8 months ago

UPDATE

I posted this before testing out an older version of godot and it seems to work just great! But as in the github issue, that is because of changes with how the protocols worked and what headers are sent!

Here is the code for use in Godot 3.1.1:

extends Node

var _client = WebSocketClient.new()

func _ready():
	print("connecting...")
	_client.connect("connection_closed", self, "ws_closed")
	_client.connect("connection_error", self, "ws_connection_error")
	_client.connect("connection_established", self, "ws_connection_established")
	_client.connect("server_close_request", self, "ws_close_request")
	_client.connect_to_url("wss://ws.revolt.chat/?version=1&format=json&token={token}")

func ws_closed(clean):
	if !clean:
		print("websocket closed")
	else:
		print("websocket closed cleanly")

func ws_connection_error():
	print("websocket connection failed")

func ws_connection_established(protocol):
	print("we're connected using protocol: ", protocol)

func ws_close_request(code, reason):
	print("closed with code: ", code, " and reason: ", reason)

func _process(delta):
	if _client.get_connection_status() == WebSocketClient.CONNECTION_DISCONNECTED:
		return
	print(_client.get_peer(1).get_packet().get_string_from_utf8())
	_client.poll()
[โ€“] MarshReaper 3 points 8 months ago

I wouldn't have gotten here without doing almost all of the previous steps. I even learned a lot about Godot and other libraries.

To solve this issue, go to PROJECT SETTINGS -> NETWORK -> LIMITS -> Max In Buffer (KB) & Max Out Buffer (KB) to a generous 1024 AND (I think) set Max Buffer (Power of 2) to a whopping 256.