コード例 #1
0
        public static void AcceptNewClient(IAsyncResult ar)
        {
            Console.WriteLine("A new Client has contacted the Server.");
            NewConnectionState asyncState = (NewConnectionState)ar.AsyncState;
            Socket             socket     = null;

            try
            {
                socket         = asyncState.listener.EndAcceptSocket(ar);
                socket.NoDelay = true;
            }
            catch (Exception exception1)
            {
                Console.WriteLine(exception1.ToString());
                asyncState.listener.BeginAcceptSocket(new AsyncCallback(Networking.AcceptNewClient), asyncState);
                return;
            }
            SocketState state2 = new SocketState
            {
                call_me    = asyncState.callMe,
                workSocket = socket
            };

            state2.call_me(state2);
            asyncState.listener.BeginAcceptSocket(new AsyncCallback(Networking.AcceptNewClient), asyncState);
        }
コード例 #2
0
        public static void ServerAwaitingClientLoop(Action <SocketState> call_this)
        {
            Console.WriteLine("Server is up. Awaiting first client");
            TcpListener l = new TcpListener(IPAddress.Any, 0x2af8);

            try
            {
                l.Start();
                NewConnectionState state = new NewConnectionState(call_this, l);
                l.BeginAcceptSocket(new AsyncCallback(Networking.AcceptNewClient), state);
            }
            catch (Exception exception1)
            {
                Console.WriteLine(exception1.ToString());
            }
        }