예제 #1
0
파일: Client.cs 프로젝트: p3NTech/ShadeMsg
 private void Background_receive_DoWork(object sender, DoWorkEventArgs e)
 {
     while (true)
     {
         if (tcpClient.Connected)
         {
             byte[] data   = new byte[1024];
             Stream stream = tcpClient.GetStream();
             int    k      = stream.Read(data, 0, data.Length);
             NewPacket(PacketEncryption.DecryptPacket(Encoding.UTF8.GetString(data).Trim('\0'), password));
         }
         Thread.Sleep(1000);
     }
 }
예제 #2
0
        private void BackgroundReceiver_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!backgroundReceiver.CancellationPending)
            {
                byte[] data = new byte[1024];

                if (socket.Connected)
                {
                    try
                    {
                        socket.Receive(data);
                        string data_string = Encoding.UTF8.GetString(data).Trim('\0');
                        Packet packet      = PacketEncryption.DecryptPacket(data_string, password);
                        NewPacket(packet, this);
                    }
                    catch
                    {
                        Disconected(this);
                    }
                }
            }
        }