private void OnClientConnected(AsynchronousSocket clientSocket) { if (ClientConnected != null) { ClientConnected.Invoke(clientSocket, new EventArgs()); } }
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); }
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()); } }
public void EncryptAndSend(AsynchronousSocket socket, string plainText) { byte[] bytes = ASCIIEncoding.ASCII.GetBytes(plainText); EncryptAndSend(socket, bytes); }
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); }
void closerSocket_Connected(object sender, EventArgs e) { AsynchronousSocket closerSocket = (AsynchronousSocket)sender; closerSocket.Disconnect(); }