コード例 #1
0
        private void ConnectCallback_obsolete(IAsyncResult ar)
        {
            TcpClient client = null;

            try
            {
                client = (TcpClient)ar.AsyncState;
                client.EndConnect(ar);
                client.NoDelay = true;

                RemoteState = new RemoteHostState(client);
                RemoteState.GotDataToSend += new EventHandler <EventArgs>(RemoteState_GotDataToSend);
                RemoteState.Stream.BeginRead(RemoteState.ReadBuffer, 0, RemoteState.ReadBuffer.Length, new AsyncCallback(RecvCallback_obsolete), null);

                OnConnected();
            }
            catch
            {
                if (RemoteState != null)
                {
                    RemoteState.Close();
                    RemoteState = null;
                }
                else if (client != null)
                {
                    client.Close();
                    client = null;
                }

                OnFailedConnect();
            }
        }
コード例 #2
0
ファイル: ServerListener.cs プロジェクト: chiendangmr/ChienCG
        void CloseConnection(RemoteHostState state, bool remote, Exception ex)
        {
            if (state != null)
            {
                lock (clients)
                    clients.Remove(state);
                IPEndPoint remoteHost = state.EndPoint;
                state.GotDataToSend -= state_GotDataToSend;
                state.Close();

                OnClientConnectionStateChanged(remoteHost, false, ex, remote);
            }
        }
コード例 #3
0
ファイル: ServerConnection.cs プロジェクト: Elyanas/Framework
        private void ConnectCallback_obsolete(IAsyncResult ar)
        {
            TcpClient client = null;
            try
            {
                client = (TcpClient)ar.AsyncState;
                client.EndConnect(ar);
                client.NoDelay = true;

                RemoteState = new RemoteHostState(client);
                RemoteState.GotDataToSend +=new EventHandler<EventArgs>(RemoteState_GotDataToSend);
                RemoteState.Stream.BeginRead(RemoteState.ReadBuffer, 0, RemoteState.ReadBuffer.Length, new AsyncCallback(RecvCallback_obsolete), null);

                OnConnected();
            }
            catch
            {
                if (RemoteState != null)
                {
                    RemoteState.Close();
                    RemoteState = null;
                }
                else if (client != null)
                {
                    client.Close();
                    client = null;
                }

                OnFailedConnect();
            }
        }
コード例 #4
0
ファイル: ServerListener.cs プロジェクト: Elyanas/Framework
        void CloseConnection(RemoteHostState state, bool remote, Exception ex)
        {
            if (state != null)
            {
                lock (clients)
                    clients.Remove(state);
                IPEndPoint remoteHost = state.EndPoint;
                state.GotDataToSend -= state_GotDataToSend;
                state.Close();

                OnClientConnectionStateChanged(remoteHost, false, ex, remote);
            }
        }