GetSocket() public méthode

public GetSocket ( ) : Socket
Résultat Socket
Exemple #1
0
        private static void ReceiveCallback(IAsyncResult ar)
        {
            ClientStateObject state = (ClientStateObject)ar.AsyncState;
            TcpClient         t     = state.c;
            Socket            s     = t.GetSocket();

            if (s == null)
            {
                return;
            }
            try
            {
                int read = s.EndReceive(ar);
                if (read > 0)
                {
                    t.onReceive(state.buffer, read);
                    s.BeginReceive(state.buffer, 0, state.buffer.Length, 0, new AsyncCallback(ReceiveCallback), state);
                }
                else
                {
                    t.onClose(s);
                }
            }
            catch (System.Exception ex)
            {
                t.onClose(s);
                Log.Instance().WriteLog(ex.Message);
                Log.Instance().WriteLog(ex.StackTrace);
            }
        }
Exemple #2
0
        private static void ConnectCallback(IAsyncResult ar)
        {
            TcpClient t = (TcpClient)ar.AsyncState;

            try
            {
                Socket s = t.GetSocket();
                s.EndConnect(ar);
                t.onConnect(true);
                ClientStateObject state = new ClientStateObject();
                state.s = s;
                state.c = t;
                s.BeginReceive(state.buffer, 0, state.buffer.Length, 0, new AsyncCallback(ReceiveCallback), state);
            }
            catch (System.Exception ex)
            {
                t.onConnect(false);

                //Log.Instance().WriteLog(ex.Message);
                //Log.Instance().WriteLog(ex.StackTrace);
            }
        }