The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

This code works as expected wen exported to HTML5. It does not work if I run it from the editor on mac, i get disconnected immediately. From the documentation it seems it should work as long as I poll(). I should also mention this works fine against my own nodejs websocket server, it just seems to have issues with external 3rd party servers like server and the twitch irc server (which is actually what I'm eventually hoping to connect to.

extends Control

var client =
var write_mode = WebSocketPeer.WRITE_MODE_TEXT

func _ready():
    client.connect("connection_established", self, "started")
    client.connect("connection_error", self, "error")
    client.connect("connection_closed", self, "closed")
    client.connect("data_received", self, "read")

func start():

func _on_Button_pressed():
    if client.get_connection_status() == WebSocketClient.CONNECTION_DISCONNECTED:

func _process(delta):
    if client.get_connection_status() == WebSocketClient.CONNECTION_DISCONNECTED:


func started(protocol):
    client.get_peer(1).put_packet(encode_data("hello there sir",write_mode))

func error(args):

func closed(clean):
    print('connection closed')

func read(p_id=1):
    print('receiving data: ' + decode_data(client.get_peer(1).get_packet(),true))

func encode_data(data, mode):
    return data.to_utf8() if mode == WebSocketPeer.WRITE_MODE_TEXT else var2bytes(data)

func decode_data(data, is_string):
    return data.get_string_from_utf8() if is_string else bytes2var(data)
in Engine by (115 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.