nhn / socket.io-client-unity3d

socket.io-Client for Unity3D, which is compatible with socket.io v1.x
Other
167 stars 42 forks source link

Reconnect after an initial connection failure #34

Open sfranzyshen opened 6 years ago

sfranzyshen commented 6 years ago

I have a scenario where the unity socket.io client might get started before the server is ready for connections ... I would like to have the client code repeatedly attempt connection until a connection is made. I'm having problems figuring out how ... this doesn't work

socket.On(SystemEvents.connectError , (Exception e) => {
    Debug.Log("Socket.io Connection Error: " + e.ToString());
    socket = Socket.Connect(serverUrl);
}

I see changes in the develop branch for disconnect and reconnect ... but when I try and use Socket.Reconnect(socket) I get errors ...

sfranzyshen commented 6 years ago

added ... to Socket.cs ...

        /// <summary>
        /// Reconnects the socket which is disconnected
        /// </summary>
        /// <param name="socket"></param>
        public static void Reconnect(Socket socket) {
            SocketManager.Instance.Reconnect(socket, 1);
        }

then (in the Connect.cs example) catch event connectError and try again ... using Socket.Reconnect()

socket.On(SystemEvents.connectError , (Exception e) => {
    Debug.Log("Socket.io Connection Error: " + e.ToString());
    Socket.Reconnect(socket);
});