public virtual void OnTcpClientConnect(IAsyncResult asyn) { TcpClientConnected?.Invoke(this, new TWSTcpClientConnectedEventArgs(this, null)); try { // Here we complete/end the BeginAccept() asynchronous call // by calling EndAccept() - which returns the reference to // a new Socket object var tc = _listener.EndAcceptTcpClient(asyn); _clientCount++; //var s = new BufferedReadStream(tc.GetStream(), DEFAULT_BUFFER_SIZE); var s = tc.GetStream(); var connection = new TWSServerClientHandler(this, s); lock (_clients) { _clients.Add(connection); } connection.Start(); // Since the main Socket is now free, it can go back and wait for // other clients who are attempting to connect _listener.BeginAcceptTcpClient(_connectCallback, null); } catch (ObjectDisposedException) { Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n"); } catch (SocketException se) { OnError(new TWSError(TWSErrors.NO_VALID_CODE, se.Message)); } }
public virtual void OnTcpClientConnect(IAsyncResult asyn) { if (TcpClientConnected != null) TcpClientConnected(this, new TWSTcpClientConnectedEventArgs(this, null)); try { // Here we complete/end the BeginAccept() asynchronous call // by calling EndAccept() - which returns the reference to // a new Socket object TcpClient tc = _listener.EndAcceptTcpClient(asyn); _clientCount++; //var s = new BufferedReadStream(tc.GetStream(), DEFAULT_BUFFER_SIZE); NetworkStream s = tc.GetStream(); var connection = new TWSServerClientHandler(this, s); lock (_clients) { _clients.Add(connection); } connection.Start(); // Since the main Socket is now free, it can go back and wait for // other clients who are attempting to connect _listener.BeginAcceptTcpClient(_connectCallback, null); } catch (ObjectDisposedException) { Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n"); } catch (SocketException se) { OnError(new TWSError(TWSErrors.NO_VALID_CODE, se.Message)); } }