public void CreateNewConnection() { var args = new SocketAsyncEventArgs(); args.Completed += Completed; // Куда подключаться. args.RemoteEndPoint = Parent.ConnectTo; var socket = new TcpSocket(); _socket = socket; StartConnect(socket, args); }
private void StartConnect(TcpSocket socket, SocketAsyncEventArgs e) { lock (Parent.Connections) { Status = ConnectionStatus.Connecting; StatusChanged?.Invoke(this, Status); if (socket.IsDisposed) { e.Dispose(); return; } } if (!socket.ConnectAsync(e)) { Completed(socket, e); } }
private void SocketConnection_StartingTunneling(object sender, TcpSocket socket) { // Сокетом теперь полностью владеет SocketConnection. socket.Disposed -= Socket_Disposed; Parent.OnTunnelCreated(this); lock (Parent.Connections) { Parent.Connections.Remove(this); if (Parent.Connections.Count < Parent._maxConnections) { var newCon = new Connection(Parent); Parent.Connections.Add(newCon); Parent.OnNewConnection(newCon); newCon.CreateNewConnection(); } } }