private async Task <IObservable <IHttpRequestReponse> > GetUdpMulticastRequestResponseObservable(
            string ipAddr,
            int port,
            ICommunicationInterface communicationInterface = null,
            bool allowMultipleBindToSamePort = false)
        {
            _udpMultiCastListener = new UdpSocketMulticastClient();

            var observeUdpRequest = await _udpMultiCastListener.ObservableMulticastListener(
                ipAddr,
                port,
                communicationInterface,
                allowMultipleBindToSamePort);

            var observable = Observable.Create <IHttpRequestReponse>(
                obs =>
            {
                var disp = observeUdpRequest.Subscribe(
                    udpSocket =>
                {
                    var stream         = new MemoryStream(udpSocket.ByteData);
                    var requestHandler = new HttpParserDelegate
                    {
                        HttpRequestReponse =
                        {
                            RemoteAddress = udpSocket.RemoteAddress,
                            RemotePort    = int.Parse(udpSocket.RemotePort),
                            RequestType   = RequestType.UDP
                        }
                    };

                    var result = _httpStreamParser.Parse(requestHandler, stream, Timeout);
                    obs.OnNext(result);
                },
                    ex =>
                {
                    _udpMultiCastListener.Dispose();
                    obs.OnError(ex);
                },
                    () =>
                {
                    _udpMultiCastListener.Dispose();
                    obs.OnCompleted();
                });

                return(disp);
            });

            return(observable);
        }
Example #2
0
        public void Dispose()

        {
            _udpClient.Dispose();
        }