Esempio n. 1
0
        //Once we receive Data from the server...
        private void ReceiveCallback(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;

            //Once a client is disconnected from the server, the server is still online for other clients.
            try
            {
                //The byte length of the data we are receiving
                int received = socket.EndReceive(ar);
                if (received <= 0)
                {
                    CloseClient(index);
                }
                else
                {
                    byte[] dataBuffer = new byte[received];
                    Array.Copy(_buffer, dataBuffer, received);
                    ServerHandleNetworkPackets.HandleNetworkInformation(index, dataBuffer);
                    socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket);
                }
            }
            catch (Exception ex)
            {
                CloseClient(index);
            }
        }
Esempio n. 2
0
        static void Main(String[] args)
        {
            ServerHandleNetworkPackets.InitializeNetworkPackages();
            ServerTCP.SetupServer();

            Console.ReadLine();
        }