public ProtocolAdapter(RequestHandler requestHandler, IRequestManager requestManager, IPayloadSender payloadSender, IPayloadReceiver payloadReceiver, object handlerContext = null) { _requestHandler = requestHandler; _handlerContext = handlerContext; _requestManager = requestManager; _payloadSender = payloadSender; _payloadReceiver = payloadReceiver; _sendOperations = new SendOperations(_payloadSender); _streamManager = new StreamManager(OnCancelStream); _assemblerManager = new PayloadAssemblerManager(_streamManager, OnReceiveRequestAsync, OnReceiveResponseAsync); _payloadReceiver.Subscribe(_assemblerManager.GetPayloadStream, _assemblerManager.OnReceive); }
/// <summary> /// Initializes a new instance of the <see cref="WebSocketServer"/> class. /// Throws <see cref="ArgumentNullException"/> on null arguments. /// </summary> /// <param name="socket">The <see cref="WebSocket"/> of the underlying connection for this server to be built on top of.</param> /// <param name="requestHandler">A <see cref="RequestHandler"/> to process incoming messages received by this server.</param> public WebSocketServer(WebSocket socket, RequestHandler requestHandler) { if (socket == null) { throw new ArgumentNullException(nameof(socket)); } _websocketTransport = new WebSocketTransport(socket); _requestHandler = requestHandler ?? throw new ArgumentNullException(nameof(requestHandler)); _requestManager = new RequestManager(); _sender = new PayloadSender(); _sender.Disconnected += OnConnectionDisconnected; _receiver = new PayloadReceiver(); _receiver.Disconnected += OnConnectionDisconnected; _protocolAdapter = new ProtocolAdapter(_requestHandler, _requestManager, _sender, _receiver); }
/// <summary> /// Initializes a new instance of the <see cref="NamedPipeServer"/> class. /// Throws <see cref="ArgumentNullException"/> on null arguments. /// </summary> /// <param name="baseName">The named pipe to connect to.</param> /// <param name="requestHandler">A <see cref="RequestHandler"/> to process incoming messages received by this server.</param> /// <param name="autoReconnect">Optional setting to determine if the server sould attempt to reconnect /// automatically on disconnection events. Defaults to true. /// </param> public NamedPipeServer(string baseName, RequestHandler requestHandler, bool autoReconnect = true) { if (string.IsNullOrWhiteSpace(baseName)) { throw new ArgumentNullException(nameof(baseName)); } _baseName = baseName; _requestHandler = requestHandler ?? throw new ArgumentNullException(nameof(requestHandler)); _autoReconnect = autoReconnect; _requestManager = new RequestManager(); _sender = new PayloadSender(); _sender.Disconnected += OnConnectionDisconnected; _receiver = new PayloadReceiver(); _receiver.Disconnected += OnConnectionDisconnected; _protocolAdapter = new ProtocolAdapter(_requestHandler, _requestManager, _sender, _receiver); }
/// <summary> /// Initializes a new instance of the <see cref="WebSocketClient"/> class. /// Throws <see cref="ArgumentNullException"/> if URL is null, empty, or whitespace. /// </summary> /// <param name="url">The URL of the remote server to connect to.</param> /// <param name="requestHandler">Optional <see cref="RequestHandler"/> to process incoming messages received by this server.</param> /// <param name="handlerContext">Optional context for the <see cref="RequestHandler"/> to operate within.</param> public WebSocketClient(string url, RequestHandler requestHandler = null, object handlerContext = null) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } _url = url; _requestHandler = requestHandler; _requestManager = new RequestManager(); _sender = new PayloadSender(); _receiver = new PayloadReceiver(); _protocolAdapter = new ProtocolAdapter(_requestHandler, _requestManager, _sender, _receiver, handlerContext); IsConnected = false; }