/// Fire the DataReceived event if it exists. protected virtual void OnDataReceived(TcpServerEventArgs e) { if (DataReceived != null) { try { DataReceived(this, e); } catch (Exception ex) { // Close the connection if the application threw an exception that is caught here by the server. e.ConnectionState.Close(); csList.Remove(e.ConnectionState); YucoDebugger.instance.LogError("OnDataReceived: DataReceived(this, e) encountered exception", "OnDataReceived", "TCPServer"); TcpLibApplicationExceptionEventArgs appErr = new TcpLibApplicationExceptionEventArgs(ex); try { OnHandleApplicationException(appErr); YucoDebugger.instance.Log("OnDataReceived: OnHandleApplicationException(appErr)", "OnDataReceived", "TCPServer"); } catch (Exception ex2) { // the exception handler threw an exception... YucoDebugger.instance.LogError("OnDataReceived: ex2" + ex2, "OnDataReceived", "TCPServer"); } } } }
// === TCP events firing ================================================================================================================================================= /// Fire the Connected event if it exists. protected virtual void OnConnected(TcpServerEventArgs e) { if (Connected != null) { try { Connected(this, e); // Start Receiving message e.ConnectionState.Connection.BeginReceive(e.ConnectionState.Buffer, 0, e.ConnectionState.Buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), e.ConnectionState); // Push to array csList.Add(e.ConnectionState); } catch (Exception ex) { // Close the connection if the application threw an exception that is caught here by the server. e.ConnectionState.Close(); TcpLibApplicationExceptionEventArgs appErr = new TcpLibApplicationExceptionEventArgs(ex); YucoDebugger.instance.LogError("OnDataReceived: Connected(this, e) encountered exception", "OnConnected", "TCPServer"); try { OnHandleApplicationException(appErr); YucoDebugger.instance.LogWarning("OnConnected: OnHandleApplicationException(appErr)", "OnConnected", "TCPServer"); } catch (Exception ex2) { // the exception handler threw an exception... YucoDebugger.instance.LogError("OnConnected: ex2" + ex2, "OnConnected", "TCPServer"); } } } }
/// Fire the Disonncted event if it exists. protected virtual void OnDisconnected(TcpServerEventArgs e) { if (Disconnected != null) { try { Disconnected(this, e); csList.Remove(e.ConnectionState); } catch (Exception ex) { YucoDebugger.instance.LogError("OnDisconnected: ex" + ex, "OnDisconnected", "TCPServer"); } } }