コード例 #1
0
ファイル: TcpConnection.cs プロジェクト: Marcel-B/Mqtt
        public TcpConnection(Socket socket)
        {
            _socket   = socket;
            _endPoint = socket.RemoteEndPoint;

            _sender   = new SocketSender(_socket, PipeScheduler.ThreadPool);
            _receiver = new SocketReceiver(_socket, PipeScheduler.ThreadPool);
        }
コード例 #2
0
        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;
        }