Esempio n. 1
0
 /// <summary>
 /// Called when the authentication bytes have been sent.
 /// </summary>
 /// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param>
 private void OnSent(IAsyncResult ar)
 {
     try {
         Endpoint.EndSend(ar);
         Buffer = new byte[2];
         Endpoint.BeginReceive(Buffer, 0, 2, SocketFlags.None, OnReceive, Endpoint);
     } catch (Exception e) {
         _callBack(e);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Called when the socket received an authentication reply.
 /// </summary>
 /// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param>
 private void OnReceive(IAsyncResult ar)
 {
     try {
         Received += Endpoint.EndReceive(ar);
         if (Received == Buffer.Length)
         {
             if (Buffer[1] == 0)
             {
                 _callBack(null);
             }
             else
             {
                 throw new SocksProxyException("Username/password combination not accepted.");
             }
         }
         else
         {
             Endpoint.BeginReceive(Buffer, Received, Buffer.Length - Received, SocketFlags.None, OnReceive, Endpoint);
         }
     } catch (Exception e) {
         _callBack(e);
     }
 }