GetSocket() public method

public GetSocket ( ) : Socket
return Socket
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }