//--------------------------------------------------------------------- public void Update(float elapsed_tm) { if (mSession != null) { mSession.Update(); } while (true) { SocketEvent socket_event; socket_event.type = eSocketEventType.Null; socket_event.client = null; socket_event.args = null; lock (LockWorker) { if (mSocketEvent.Count > 0) { socket_event = mSocketEvent.Dequeue(); } } if (socket_event.type == eSocketEventType.Null) { break; } switch (socket_event.type) { case eSocketEventType.Connected: { if (OnSocketConnected != null) { OnSocketConnected.Invoke(null, socket_event.args); } } break; case eSocketEventType.Closed: { if (OnSocketClosed != null) { OnSocketClosed.Invoke(null, socket_event.args); } } break; case eSocketEventType.Error: { if (OnSocketError != null) { OnSocketError.Invoke(null, (SocketErrorEventArgs)socket_event.args); } } break; } } }
//------------------------------------------------------------------------- void _onSocketClosed(object client, EventArgs args) { //this.tcpSocket = null; if (OnSocketClosed != null) { OnSocketClosed.Invoke(this, args); } }
private static void Trace(string LogText, Socket TcpSocket) { OnSocketClosed?.Invoke(LogText, TcpSocket); foreach (TraceListener debug in Debug.Listeners) { debug.WriteLine(LogText); } if (isConnected) { isConnected = false; Reconnect(); } }
//--------------------------------------------------------------------- public void Close() { if (mSession != null) { mSession.Dispose(); mSession = null; if (OnSocketClosed != null) { OnSocketClosed.Invoke(null, EventArgs.Empty); } } }
public void CloseSocket() { try { try { var closeTask = m_webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", CancellationToken.None); } catch { } m_webSocket = null; OnSocketClosed?.Invoke(this, null); } catch { } }
private void NotifyOnSocketClosed(string socketName) => OnSocketClosed?.Invoke(socketName);