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")
var ONLINE_MODE_STATE = true
func _ready():
connect_url()
func connect_url():
if ONLINE_MODE_STATE:
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...")
connect_url()
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.