Exemple #1
0
        public override Stream CreateStream()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.NoDelay     = true;
            socket.LingerState = new LingerOption(false, 0);

            IAsyncResult asyncResult = socket.BeginConnect(m_ipEndPoint, null, null);

            if (asyncResult.AsyncWaitHandle.WaitOne(2000, false))
            {
                socket.EndConnect(asyncResult);
            }
            else
            {
                socket.Close();
                throw new IOException("Connect failed");
            }

            AsyncNetworkStream stream = new AsyncNetworkStream(socket, true);

            return(stream);
        }
Exemple #2
0
        public override Stream CreateStream()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.NoDelay = true;
            socket.LingerState = new LingerOption(false, 0);

            IAsyncResult asyncResult = socket.BeginConnect(m_ipEndPoint, null, null);

            if (asyncResult.AsyncWaitHandle.WaitOne(2000, false))
            {
                socket.EndConnect(asyncResult);
            }
            else
            {
                socket.Close();
                throw new IOException("Connect failed");
            }

            AsyncNetworkStream stream = new AsyncNetworkStream(socket, true);

            return stream;
        }