0 votes

Hi everyone,
I am currently working on a reconnection mechanism with WebsocketClient when the internet goes down or when the mobile data is finished or disconnected from the internet. The following code is what I have been trying to do:

var ws_client = WebSocketClient.new()
ws_client.connect("connection_closed", self, "_closed")
ws_client.connect("connection_error", self, "_closed")
ws_client.connect("connection_established", self, "_connected")
ws_client.connect("data_received", self, "_on_data")

func _ready():

func connect_url():
        var err = ws_client.connect_to_url(websocket_url) #, ["lws-mirror-protocol"])
            if err != OK:
                print("Unable to connect...")

func _closed(was_clean = false):
    print("Closed, clean: ", was_clean)
    print("Retrying to reconnect...")

func _connected(proto = ""):
    print("Connected with protocol: ", proto)

The problem is that on a computer the websocket client reconnects normally when there is an interruption, but on Android the game crashes and is closed.

Thanks for contributions, i appreciate.

Godot version 3.5.1
in Engine by (32 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.