コード例 #1
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;

            try
            {
                int received = socket.EndReceive(ar);
                if (received <= 0)
                {
                    CloseClient(index);
                }
                else
                {
                    byte[] dataBuffer = new byte[received];
                    Array.Copy(Buffer, dataBuffer, received);
                    NetworkDataHandler.HandleNetworkInformation(index, dataBuffer);
                    socket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket);
                }
            }
            catch (Exception ex)
            {
                CloseClient(index);
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
コード例 #2
0
 public static void SetupServer()
 {
     for (int i = 0; i < Constants.MAX_CONNECTIONS; i++)
     {
         Clients[i] = new Client();
     }
     ServerSocket.Bind(new IPEndPoint(IPAddress.Any, 5555));
     ServerSocket.Listen(10);
     ServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);
     NetworkDataHandler.InitializeNetworkPackages();
 }