I'm working on a MMO game in Godot, but I'm stuck on solving an issue with websockets.
I made a server in Python a while ago, with the
websockets package. I tested it with a JS client and everything worked correctly.
However, when I try to connect to it with Godot, the game can't connect to the server. There are no errors or anything, but
client.get_connection_status() is set to
CONNECTION_CONNECTING) and never changes.
The full code:
var client = WebSocketClient.new()
var last_status = -1
# Set events
client.connect("connection_established", self, "started")
client.connect("connection_error", self, "error", ["error"])
client.connect("connection_closed", self, "error", ["closed"])
client.connect("data_received", self, "read")
var status = client.get_connection_status()
if status != last_status:
last_status = status
if status == WebSocketClient.CONNECTION_DISCONNECTED:
# Connect to server
client.verify_ssl = false
print(": ", arg)
# Read message
var packet = client.get_peer(1).get_packet()
print("Received, %s" % [packet])
# Send message
None of the signals ever gets triggered. The app produces the log:
** Debug Process Started **
OpenGL ES 3.0 Renderer: GeForce GT 640/PCIe/SSE2
TL;DR There are no errors - the client just never ends connecting. What can be the reason of this? The server never receives any connections from Godot.
EDIT: I exported the project to HTML and uploaded it to my server. I'm getting the message
Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received. StackOverflow tells me it's because the app requests with an unsupported subprotocol.
EDIT 2: I fixed the issue with subprotocols, but only for the HTML version. Doesn't work in other versions anyway.