void Unsubscribe(Connector conn) { conn.ExceptionEncountered -= conn_ExceptionEncountered; conn.BytesReceived -= conn_BytesReceived; conn.Connected -= conn_Connected; conn.ConnectionLost -= conn_ConnectionLost; }
public void StartClientConnection(TcpClient client) { Connector conn = new Connector(Port); connections.Add(conn.ID, conn); Subscribe(conn); conn.Start(client); OnEvent(NewConnectionCreated, new ConnectionEventArgs(conn.ID)); }
public void StartServerConnection() { if (IsConnectedToClients) { throw new InvalidOperationException("Cannot set up a server connection when already listening on clients."); } IsConnectedToServer = true; Connector conn = new Connector(Port); connections.Add(conn.ID, conn); TcpClient client = new TcpClient(); Subscribe(conn); try { client.Connect(Host, Port); conn.Start(client); OnEvent(NewConnectionCreated, new ConnectionEventArgs(conn.ID)); } catch (SocketException) { if (UnableToConnect != null) { UnableToConnect(this, EventArgs.Empty); } } catch (Exception) { if (CrashOnException) { throw; } } }