java.lang.Object
org.cybergarage.upnp.ssdp.HTTPUSocket
- Direct Known Subclasses:
SSDPSearchResponseSocket
UDP socket implementation for SSDP (Simple Service Discovery Protocol) communication.
This class provides UDP socket functionality specifically designed for SSDP operations in UPnP networks. It handles both unicast and multicast UDP communication for device discovery and advertisement.
Key features:
- UDP unicast socket management
- IPv4 and IPv6 support
- Packet sending and receiving
- Timestamp tracking for received packets
- Network interface binding
This class is used by SSDP components to send discovery messages (M-SEARCH) and receive device advertisements (NOTIFY messages) over UDP multicast and unicast communication.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String/////////////////////////////////////////////private DatagramSocket/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescriptionOpen a socket bound to any free local port.HTTPUSocket(int bindPort) Open a socket bound to a given local port on any address.HTTPUSocket(String bindAddr, int bindPort) Open a socket bound to a given local address and port.Method Summary
Public MethodsModifier and TypeMethodDescriptionbooleanclose()Close the socket and clear the reference to it.protected voidfinalize()Close the socket when the object is garbage collected.Open a datagram socket on an ephemeral port, for SSDP unicast traffic.Return the local address this socket reports.Return the underlying datagram socket, for callers that need it directly.booleanopen()Open a datagram socket on an ephemeral port, replacing any open socket.booleanopen(int bindPort) Open a datagram socket bound to a local port with address reuse allowed.booleanOpen a datagram socket bound to a local address and port.booleanSend one SSDP message as a UDP datagram.receive()Block until one datagram arrives, then wrap it as an SSDP packet.voidsetLocalAddress(String addr) Override the address this socket reports as its own.toString()Return the local address this socket reports.
Field Details
ssdpUniSock
/////////////////////////////////////////////localAddr
/////////////////////////////////////////////
Constructor Details
HTTPUSocket
public HTTPUSocket()Open a socket bound to any free local port.HTTPUSocket
Open a socket bound to a given local address and port.- Parameters:
bindAddr- the local address to bind the socket to, resolved by namebindPort- the local UDP port to bind, 0 for any free port
HTTPUSocket
public HTTPUSocket(int bindPort) Open a socket bound to a given local port on any address.- Parameters:
bindPort- the local UDP port to bind, 0 for any free port
Method Details
getDatagramSocket
Open a datagram socket on an ephemeral port, for SSDP unicast traffic.- Returns:
- the socket SSDP datagrams are sent and received on, null if none is open
finalize
protected void finalize()Close the socket when the object is garbage collected.setLocalAddress
Override the address this socket reports as its own.- Parameters:
addr- the address to report for this socket instead of the one it bound to
getUDPSocket
Return the underlying datagram socket, for callers that need it directly.- Returns:
- the open
DatagramSocket, or null if the socket is closed
getLocalAddress
Return the local address this socket reports.- Returns:
- the address set by
setLocalAddress(String), else the bound address, or "" if closed
open
public boolean open()Open a datagram socket on an ephemeral port, replacing any open socket.- Returns:
- true if the socket was created, false if the bind failed
open
Open a datagram socket bound to a local address and port.- Parameters:
bindAddr- the local address to bind the socket to, resolved by namebindPort- the local UDP port to bind, 0 for any free port- Returns:
- true if the socket bound to the address and port, false if either failed
open
public boolean open(int bindPort) Open a datagram socket bound to a local port with address reuse allowed.- Parameters:
bindPort- the local UDP port to bind, 0 for any free port- Returns:
- true if the socket bound with address reuse, false if the bind failed
close
public boolean close()Close the socket and clear the reference to it.- Returns:
- true if the socket is now closed, false if closing it failed
post
receive
Block until one datagram arrives, then wrap it as an SSDP packet.- Returns:
- the packet that arrived, or null if the receive failed
toString