Esempio n. 1
0
 private void OnClientConnected(AsynchronousSocket clientSocket)
 {
     if (ClientConnected != null)
     {
         ClientConnected.Invoke(clientSocket, new EventArgs());
     }
 }
Esempio n. 2
0
 public AsynchronousSocket(AsynchronousSocket listenerSocket, Socket clientSocket)
 {
     if (clientSocket == null)
     {
         throw new ArgumentNullException();
     }
     InitializeProperties();
     ListenerSocket = listenerSocket;
     IsConnected    = clientSocket.Connected; // Bad: trusting that this is correct
     this.socket    = clientSocket;
     //clientSocket.LingerState = new LingerOption(false, 0);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket,
                                  SocketOptionName.DontLinger, true);
 }
Esempio n. 3
0
        public void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            listenClientDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;

            try
            {
                Socket             handler      = listener.EndAccept(ar);
                AsynchronousSocket clientSocket = new AsynchronousSocket(this, handler);
                OnClientConnected(clientSocket);
                clientSocket.BeginReceiving();
            }
            catch (ObjectDisposedException)
            {
                // Object disposed, np, ignore it
            }
            catch (Exception ex)
            {
                OnDebug(ex.ToString());
            }
        }
Esempio n. 4
0
 public void EncryptAndSend(AsynchronousSocket socket, string plainText)
 {
     byte[] bytes = ASCIIEncoding.ASCII.GetBytes(plainText);
     EncryptAndSend(socket, bytes);
 }
Esempio n. 5
0
 public void EncryptAndSend(AsynchronousSocket socket, byte[] plainText)
 {
     // Send an encrypted byte array to the client
     byte[] encrypted = Encrypt(plainText);
     socket.Send(encrypted, 0, encrypted.Length);
 }
Esempio n. 6
0
        void closerSocket_Connected(object sender, EventArgs e)
        {
            AsynchronousSocket closerSocket = (AsynchronousSocket)sender;

            closerSocket.Disconnect();
        }