Esempio n. 1
0
        public async void ReadClientData(IAsyncResult ar)
        {
            try
            {
                if (!ClientSocket.Connected)
                {
                    Disconnected();
                    return;
                }
                else
                {
                    int Recevied = ClientSslStream.EndRead(ar);
                    if (Recevied > 0)
                    {
                        await ClientMS.WriteAsync(ClientBuffer, 0, Recevied);

                        if (!ClientBufferRecevied)
                        {
                            if (ClientMS.Length == 4)
                            {
                                ClientBuffersize = BitConverter.ToInt32(ClientMS.ToArray(), 0);
                                ClientMS.Dispose();
                                ClientMS = new MemoryStream();
                                if (ClientBuffersize > 0)
                                {
                                    ClientBuffer = new byte[ClientBuffersize];
                                    Debug.WriteLine("/// Server Buffersize " + ClientBuffersize.ToString() + " Bytes  ///");
                                    ClientBufferRecevied = true;
                                }
                            }
                        }
                        else
                        {
                            Settings.Received += Recevied;
                            BytesRecevied     += Recevied;
                            if (ClientMS.Length == ClientBuffersize)
                            {
                                ThreadPool.QueueUserWorkItem(Packet.Read, new object[] { ClientMS.ToArray(), this });
                                ClientBuffer = new byte[4];
                                ClientMS.Dispose();
                                ClientMS             = new MemoryStream();
                                ClientBufferRecevied = false;
                            }
                        }
                        ClientSslStream.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null);
                    }
                    else
                    {
                        Disconnected();
                        return;
                    }
                }
            }
            catch
            {
                Disconnected();
                return;
            }
        }
Esempio n. 2
0
 private void EndAuthenticate(IAsyncResult ar)
 {
     try
     {
         ClientSslStream.EndAuthenticateAsServer(ar);
         ClientBuffer = new byte[4];
         ClientMS     = new MemoryStream();
         ClientSslStream.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null);
     }
     catch
     {
         ClientSslStream?.Dispose();
         ClientSocket?.Dispose();
     }
 }
Esempio n. 3
0
 private void EndAuthenticate(IAsyncResult ar)
 {
     try
     {
         ClientSslStream.EndAuthenticateAsServer(ar);
         ClientBuffer = new byte[4];
         ClientMS     = new MemoryStream();
         ClientSslStream.BeginRead(ClientBuffer, 0, ClientBuffer.Length, ReadClientData, null);
     }
     catch
     {
         //Settings.Blocked.Add(ClientSocket.RemoteEndPoint.ToString().Split(':')[0]);
         ClientSslStream?.Dispose();
         ClientSocket?.Dispose();
     }
 }