private void HandleClientHello(ClientContext context, Message message) { switch (message.Type) { case MessageType.Hello: InvokeHelloReceived(context.Client); InvokeConnecting(context.Client); context.AcquireWriteLock(); try { context.Writer.WriteHello(); } finally { context.ReleaseWriteLock(); } InvokeHelloSent(context.Client); lock (_clients) { _clients.Add(context); } InvokeConnected(context.Client); break; default: context.AcquireWriteLock(); try { context.Writer.WriteError("Hello expected"); } finally { context.ReleaseWriteLock(); } break; } }
private void HandleArbitraryMessage(ClientContext context, Message message) { switch (message.Type) { case MessageType.Data: HandleData(context, message.Data); break; case MessageType.Goodbye: HandleGoodbyeMessage(context); break; default: throw new InvalidOperationException(); } }