protected void StartReceive(UDPAsyncReceiveState <EndpointConfiguration> state) { EndPoint remoteEP = new IPEndPoint(state.Endpoint.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0); try { state.Socket.BeginReceiveFrom(state.Buffer, 0, state.Buffer.Length, SocketFlags.None, ref remoteEP, OnSSDPReceive, state); } catch (Exception e) // SocketException and ObjectDisposedException { UPnPConfiguration.LOGGER.Info("SSDPServerController: UPnP SSDP subsystem unable to receive from IP address '{0}'", e, NetworkHelper.IPAddrToString(state.Endpoint.EndPointIPAddress)); } }
private void OnSSDPReceive(IAsyncResult ar) { lock (_serverData.SyncObj) if (!_serverData.IsActive) { return; } UDPAsyncReceiveState <EndpointConfiguration> state = (UDPAsyncReceiveState <EndpointConfiguration>)ar.AsyncState; EndpointConfiguration config = state.Endpoint; Socket socket = state.Socket; try { EndPoint remoteEP = new IPEndPoint( state.Endpoint.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0); // To retrieve the remote endpoint address, it is necessary that the SocketOptionName.PacketInformation is set to true on the socket using (Stream stream = new MemoryStream(state.Buffer, 0, socket.EndReceiveFrom(ar, ref remoteEP))) { try { SimpleHTTPRequest header; SimpleHTTPRequest.Parse(stream, out header); HandleSSDPRequest(header, config, (IPEndPoint)remoteEP); } catch (Exception e) { UPnPConfiguration.LOGGER.Debug( "SSDPServerController: Problem parsing incoming packet at IP endpoint '{0}'. Error message: '{1}'", e, NetworkHelper.IPAddrToString(config.EndPointIPAddress), e.Message); } } StartReceive(state); } catch (Exception) // SocketException, ObjectDisposedException { // Socket was closed - ignore this exception UPnPConfiguration.LOGGER.Info("SSDPServerController: Stopping listening for multicast messages at IP endpoint '{0}'", NetworkHelper.IPAddrToString(config.EndPointIPAddress)); } }
protected void StartUnicastReceive(UDPAsyncReceiveState<EndpointConfiguration> state) { try { Socket socket = state.Endpoint.SSDP_UDP_UnicastSocket; EndPoint remoteEP = new IPEndPoint(state.Endpoint.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0); if (socket != null) socket.BeginReceiveFrom(state.Buffer, 0, state.Buffer.Length, SocketFlags.None, ref remoteEP, OnSSDPUnicastReceive, state); } catch (Exception e) // SocketException and ObjectDisposedException { UPnPConfiguration.LOGGER.Error("SSDPClientController: Problem receiving unicast SSDP packets: '{0}'", e.Message); } }
protected void StartReceive(UDPAsyncReceiveState<EndpointConfiguration> state) { EndPoint remoteEP = new IPEndPoint(state.Endpoint.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0); try { state.Socket.BeginReceiveFrom(state.Buffer, 0, state.Buffer.Length, SocketFlags.None, ref remoteEP, OnSSDPReceive, state); } catch (Exception e) // SocketException and ObjectDisposedException { UPnPConfiguration.LOGGER.Info("SSDPServerController: UPnP SSDP subsystem unable to receive from IP address '{0}'", e, NetworkHelper.IPAddrToString(state.Endpoint.EndPointIPAddress)); } }