public TcpConnection(Socket socket) { _socket = socket; _endPoint = socket.RemoteEndPoint; _sender = new SocketSender(_socket, PipeScheduler.ThreadPool); _receiver = new SocketReceiver(_socket, PipeScheduler.ThreadPool); }
public async Task StartAsync() { if (_socket == null) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _sender = new SocketSender(_socket, PipeScheduler.ThreadPool); _receiver = new SocketReceiver(_socket, PipeScheduler.ThreadPool); await _socket.ConnectAsync(_endPoint); } var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default); Transport = pair.Transport; _application = pair.Application; _ = ExecuteAsync(); IsConnected = true; }