Пример #1
0
        public static void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            allDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            // Create the state object.
            StateObject state = new StateObject();

            state.workSocket    = handler;
            state.clientHandler = new ClientHandler(handler, legend);

            var readyPacket = new Packets.ReadyPacket(0);

            AsynchronousSocketListener.Send(state.workSocket, readyPacket);

            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                 new AsyncCallback(ReadCallback), state);
        }
Пример #2
0
 public void SendPacket(Packet packet)
 {
     AsynchronousSocketListener.Send(handler, packet);
 }
Пример #3
0
 static void Main(string[] args)
 {
     AsynchronousSocketListener.StartListening();
     Console.WriteLine("Hello World!");
 }