// FUNC =================================================================================== //========================================================================================= public void Disconnect() { if (client == null) { return; } try { client.Dispose(); client = null; CheckSocket(); } catch (Exception error) { Debug.Log(error); } }
public void CheckSocket() { if (client == null) { client = new ClientSocketV2(port, host); client.onConnectionStarted += ClientSocket_onConnectionStarted; client.onConnectionSuccess += ClientSocket_onConnected; client.onConnectionFailed += ClientSocket_onConnectionFailed; client.onReconnectionStarted += ClientSocket_onReconnectionBegin; client.onReconnectionLimit += ClientSocket_onReconnectionLimit; client.onDisconnectionSuccess += ClientSocket_onDisconnected; client.onMessageReceived += Client_onMessageReceived; } if (!client.connected) { client.ConnectToServer(); } }
private void OnDestroy() { client?.Dispose(); client = null; // чтоб наверняка }