java.lang.Object
org.cybergarage.upnp.ssdp.HTTPMUSocket
org.cybergarage.upnp.ssdp.SSDPSearchSocket
- All Implemented Interfaces:
Runnable
Socket for sending SSDP search requests and receiving responses.
This class extends HTTPMUSocket and implements Runnable to provide asynchronous handling of SSDP search operations. It manages both sending M-SEARCH requests and receiving device responses.
Key features:
- IPv4 and IPv6 support
- Multicast search request broadcasting
- Asynchronous response reception
- Multi-threaded operation
- Network interface binding
This class is used by UPnP control points to perform device discovery by sending M-SEARCH requests to the SSDP multicast address and receiving responses from available devices on the network.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ListenerListListeners notified of each device search.private ThreadThe thread listening for searches.private booleanTrue when this socket binds an IPv6 address.Constructor Summary
ConstructorsConstructorDescriptionSSDPSearchSocket(String bindAddr, int port, String multicast) Binds the search socket for SSDP multicast traffic.SSDPSearchSocket(InetAddress bindAddr) Binds the search socket to an IPv4 or IPv6 local address.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidaddSearchListener(SearchListener listener) Registers a listener for incoming device searches.booleanOpens the socket, picking the IP version from the bind hostname.booleanOpens the socket on the given local address and multicast group.booleanopen(Inet4Address bindAddr) Opens the socket joined to the IPv4 SSDP multicast group.booleanopen(Inet6Address bindAddr) Opens the socket joined to the IPv6 SSDP multicast group.voidperformSearchListener(SSDPPacket ssdpPacket) Hands a received search request to every registered listener.voidremoveSearchListener(SearchListener listener) Unregisters a previously added search listener.voidrun()Receives and dispatches search packets until the thread is replaced.voidstart()Launches the receive thread under a name naming the multicast group.voidstop()Closes the socket and unhooks the receive thread.Methods inherited from class HTTPMUSocket
close, finalize, getLocalAddress, getLocalPort, getMulticastAddress, getMulticastInetAddress, getMulticastPort, getSocket, open, open, post, post, receive, send, send, toStringModifier and TypeMethodDescriptionbooleanclose()Close the multicast socket and leave the group.protected voidfinalize()Get the local address.intGet the source port for multicast packet.Get the multicast address string.Get the multicast inet address.intGet the destination port for multicast packet.Get the opened multicast socket.booleanOpen a multicast socket with the given string address.booleanopen(String addr, int port, InetAddress bindAddr) Open a multicast socket and join the given group.booleanpost(HTTPRequest req) Post an HTTP request using default bind settings.booleanpost(HTTPRequest req, String bindAddr, int bindPort) Post an HTTP request as a multicast message.receive()Receive a multicast packet.booleanSend a multicast message using default bind settings.booleanSend a multicast message.toString()I2P
Field Details
useIPv6Address
private boolean useIPv6AddressTrue when this socket binds an IPv6 address.deviceSearchListenerList
Listeners notified of each device search.deviceSearchThread
The thread listening for searches.
Constructor Details
SSDPSearchSocket
Binds the search socket for SSDP multicast traffic.- Parameters:
bindAddr- The address to bind the serviceport- The port used for accepting messagemulticast- The multicast address to use as destination- Throws:
IOException- if the socket cannot be bound to bindAddr
SSDPSearchSocket
Binds the search socket to an IPv4 or IPv6 local address.- Parameters:
bindAddr- the binding address for sending multicast packet- Throws:
IOException- if the socket cannot be bound to bindAddr
Method Details
open
Opens the socket joined to the IPv4 SSDP multicast group.- Parameters:
bindAddr- the IPv4 local address to send multicast packets from- Returns:
- true if and only if it open the socket
open
Opens the socket joined to the IPv6 SSDP multicast group.- Parameters:
bindAddr- the IPv6 local address to send multicast packets from- Returns:
- true if and only if it open the socket
open
Opens the socket on the given local address and multicast group.- Parameters:
bind- the local address or hostname to send multicast packets frommulticast- the destination multicast address, which must be of the same IP version as bind- Returns:
- true if and only if it open the socket
open
Opens the socket, picking the IP version from the bind hostname.- Parameters:
bindAddr- the hostname of the interface to use for sending multicast packet- Returns:
- true if and only if it open the socket
- See Also:
addSearchListener
Registers a listener for incoming device searches.- Parameters:
listener- the listener notified for every received search request
removeSearchListener
Unregisters a previously added search listener.- Parameters:
listener- the listener to stop notifying
performSearchListener
Hands a received search request to every registered listener.- Parameters:
ssdpPacket- the received search request to hand to every registered listener
run
start
public void start()Launches the receive thread under a name naming the multicast group.stop
public void stop()Closes the socket and unhooks the receive thread.