/// <summary> /// Method called when a <see cref="SocketAsyncEventArgs"/> completes an async operation. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal void OnSocketCompleted(object s, SocketAsyncEventArgs e) { try { switch (e.LastOperation) { case SocketAsyncOperation.Connect: sender = new ClientSender(sendSocketArgs); sender.Start(); OnConnected(); connector.ReleaseConnectorLock(); break; case SocketAsyncOperation.Receive: receiver.Receive(e); break; case SocketAsyncOperation.Send: sender.SendOperationCompleted(e); break; default: throw new InvalidOperationException("Unexpected SocketAsyncOperation."); } } catch (Exception exception) { OnError(exception); } }