static void Main(string[] args)
 {
     Console.Title = "Client";
     ClientDataHandle.InitializeNetworkPackages();
     ClientTCP.ConnectToServer();
     Console.ReadLine();
 }
Exemplo n.º 2
0
        private static void OnReceive()
        {
            byte[] _sizeinfo      = new byte[4];
            byte[] _receivebuffer = new byte[1024];

            int totalread = 0, currentread = 0;

            try
            {
                currentread = totalread = _clientSocket.Receive(_sizeinfo);
                if (totalread <= 0)
                {
                    Console.WriteLine("You are not connected to the server.");
                }
                else
                {
                    while (totalread < _sizeinfo.Length && currentread > 0)
                    {
                        currentread = _clientSocket.Receive(_sizeinfo, totalread, _sizeinfo.Length - totalread, SocketFlags.None);
                        totalread  += currentread;
                    }

                    int messagesize = 0;
                    messagesize |= _sizeinfo[0];
                    messagesize |= (_sizeinfo[1] << 8);
                    messagesize |= (_sizeinfo[2] << 16);
                    messagesize |= (_sizeinfo[3] << 24);

                    byte[] data = new byte[messagesize];

                    totalread   = 0;
                    currentread = totalread = _clientSocket.Receive(data, totalread, data.Length - totalread, SocketFlags.None);

                    while (totalread < messagesize && currentread > 0)
                    {
                        currentread = _clientSocket.Receive(data, totalread, data.Length - totalread, SocketFlags.None);
                        totalread  += currentread;
                    }

                    // HandleNetworkInformation;
                    ClientDataHandle.HandleNetworkInformation(data);
                }
            } catch {
                Console.WriteLine("You are not connected to the server.");
            }
        }