Пример #1
0
        public IEasyChannel RunAsClientAsync()
        {
            _localEndPoint = ConnectOptions.LocalEndPoint ?? _easyBase.GetLocalEndPoint();

            _sendIpEndPoint = ConnectOptions.RemoteEndPoint;
            _client         = new UdpClient(_localEndPoint);
            _client.BeginReceive(ReceiveCallback, _client);
            return(this);
        }
Пример #2
0
        public IEasyChannel RunAsClientAsync()
        {
            if (_tcpClient is null)
            {
                IPEndPoint localEndPoint = ConnectOptions.LocalEndPoint ?? _easyBase.GetLocalEndPoint();
                _tcpClient = new TcpClient(localEndPoint);
                _tcpClient.Connect(ConnectOptions.RemoteEndPoint);
            }

            _tcpClient.ReceiveBufferSize = _bufferPool.Length;
            _tcpClient.SendBufferSize    = _bufferPool.Length;
            NetworkStream stream = _tcpClient.GetStream();

            stream.BeginRead(_bufferPool, 0, _bufferPool.Length, HandleDataReceived, stream);
            return(this);
        }