Ejemplo n.º 1
0
        // ASYNC CALLBACK CODE
        void AcceptCallback(IAsyncResult ar)
        {
            try {
                Socket server = (Socket)ar.AsyncState;
                Socket cs = server.EndAccept (ar);

                // Start the thing listening again
                server.BeginAccept (new AsyncCallback (AcceptCallback), server);

                ClientInfo c = new ClientInfo (cs, null, null, ClientDirection.Both, false);
                c.server = this;
                // Allow the new client to be rejected by the application
                if (Connect != null) {
                    if (!Connect (this, c)) {
                        // Rejected
                        cs.Close ();
                        return;
                    }
                }
                // Initiate key exchange
                c.EncryptionType = encType;
                switch (encType) {
                case EncryptionType.None:
                    KeyExchangeComplete (c);
                    break;
                /*
                case EncryptionType.ServerKey:
                    c.encKey = GetSymmetricKey ();
                    byte[] key = ClientInfo.GetLengthEncodedVector (c.encKey);
                    cs.Send (key);
                    c.MakeEncoders ();
                    KeyExchangeComplete (c);
                    break;
                case EncryptionType.ServerRSAClientKey:
                    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ();
                    RSAParameters p = rsa.ExportParameters (true);
                    cs.Send (ClientInfo.GetLengthEncodedVector (p.Modulus));
                    cs.Send (ClientInfo.GetLengthEncodedVector (p.Exponent));
                    c.encParams = p;
                    break;
                */
                default:
                    throw new ArgumentException ("Unknown or unsupported encryption type " + encType);
                }
                clients.Add (c);

            #if MONOTOUCH
                GetHandlerThread(c).Start();
            #else
                c.BeginReceive ();
            #endif

            } catch (ObjectDisposedException) {
            } catch (SocketException) {
            } catch (Exception e) {
                SystemLogger.Log (SystemLogger.Module .CORE, null, e);
            }
        }
Ejemplo n.º 2
0
        // ASYNC CALLBACK CODE
        void AcceptCallback(IAsyncResult ar)
        {
            try {
                Socket server = (Socket)ar.AsyncState;
                Socket cs     = server.EndAccept(ar);

                // Start the thing listening again
                server.BeginAccept(new AsyncCallback(AcceptCallback), server);

                ClientInfo c = new ClientInfo(cs, null, null, ClientDirection.Both, false);
                c.server = this;
                // Allow the new client to be rejected by the application
                if (Connect != null)
                {
                    if (!Connect(this, c))
                    {
                        // Rejected
                        cs.Close();
                        return;
                    }
                }
                // Initiate key exchange
                c.EncryptionType = encType;
                switch (encType)
                {
                case EncryptionType.None:
                    KeyExchangeComplete(c);
                    break;

                /*
                 * case EncryptionType.ServerKey:
                 *      c.encKey = GetSymmetricKey ();
                 *      byte[] key = ClientInfo.GetLengthEncodedVector (c.encKey);
                 *      cs.Send (key);
                 *      c.MakeEncoders ();
                 *      KeyExchangeComplete (c);
                 *      break;
                 * case EncryptionType.ServerRSAClientKey:
                 *      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ();
                 *      RSAParameters p = rsa.ExportParameters (true);
                 *      cs.Send (ClientInfo.GetLengthEncodedVector (p.Modulus));
                 *      cs.Send (ClientInfo.GetLengthEncodedVector (p.Exponent));
                 *      c.encParams = p;
                 *      break;
                 */
                default:
                    throw new ArgumentException("Unknown or unsupported encryption type " + encType);
                }
                clients.Add(c);


#if MONOTOUCH
                GetHandlerThread(c).Start();
#else
                c.BeginReceive();
#endif
            } catch (ObjectDisposedException) {
            } catch (SocketException) {
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.CORE, null, e);
            }
        }
Ejemplo n.º 3
0
 protected virtual void HandleThreadMethod()
 {
     //SystemLogger.Log(SystemLogger.Module.CORE, "***** HandleThreadMethod started");
     // Run code in new thread with autorelease of resources
     clientInfo.BeginReceive();
 }