private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e) { if (_state != ClientState.ServerToClientHandshake) throw new Exception("Server handshake should not be received during " + _state); var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity); _state = ClientState.Ready; _connection.SetHandshakeCompleted(); _connection.Send(frame); //TODO: This is a mess. Create a better way // to identify and activate extensions. // maybe by defining extension behavior like IInboundMessageProcessor. var id = _extensionService.FindFirstExtensionId("json", "xml", "protobuf"); if (id > 0) _payloadSerializer = (((IPayloadExtension)_extensionService.Get(id))).CreatePayloadSerializer(); id = _extensionService.FindFirstExtensionId("dotnet"); if (id > 0) _dotNetExtension = (DotNetTypeExtension) _extensionService.Get(id); _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack"); if (_ackExtensionId != 0) { var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack"); var extProperties = frame.GetExtension(name); var ackExtension = (IAckExtension) _extensionService.Get(_ackExtensionId); _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage, extProperties); _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties); } _authenticationEvent.Set(); }
private void OnHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e) { Console.WriteLine(e.Handshake); switch (_state) { case ServerState.WaitingOnInitialHandshake: NegotiateHandshake(e.Handshake); break; case ServerState.WaitingOnFinalHandshake: FinalizeHandshake(e.Handshake); break; } }