Exemplo n.º 1
0
 private void BeginReceive(NetUserToken ut)
 {
     try
     {
         ut.socket.BeginReceive(ut.buffer, 0, ut.buffer.Length, SocketFlags.None, EndReceive, ut);
     }
     catch (Exception e)
     {
         print(e.Message);
     }
 }
Exemplo n.º 2
0
        public void Start()
        {
            server.Listen(maxClient);

            print("Server OK!");

            pools = new Stack <NetUserToken>();
            for (int i = 0; i < maxClient; ++i)
            {
                NetUserToken ut = new NetUserToken();
                pools.Push(ut);
            }

            server.BeginAccept(AsyncAceept, null);
        }
Exemplo n.º 3
0
 private void EndReceive(IAsyncResult rs)
 {
     try
     {
         NetUserToken ut  = rs.AsyncState as NetUserToken;
         int          len = ut.socket.EndReceive(rs);
         if (len > 0)
         {
             byte[] data = new byte[len];
             Buffer.BlockCopy(ut.buffer, 0, data, 0, len);
             ut.Receive(data);
             BeginReceive(ut);
         }
     }
     catch (Exception e)
     {
         print(e.Message);
     }
 }
Exemplo n.º 4
0
        private void AsyncAceept(IAsyncResult rs)
        {
            try
            {
                Socket client = server.EndAccept(rs);

                NetUserToken ut = pools.Pop();
                ut.socket = client;
                BeginReceive(ut);

                utList.Add(ut);

                server.BeginAccept(AsyncAceept, null);
            }
            catch (Exception e)
            {
                print(e.Message);
            }
        }