java.lang.Object
org.cybergarage.upnp.ssdp.SSDPPacket
Represents an SSDP packet received over UDP.
This class wraps a DatagramPacket to provide SSDP-specific functionality for parsing and handling UDP packets containing SSDP messages. It provides access to both the raw packet data and parsed SSDP message content.
Key features:
- DatagramPacket wrapping and management
- Remote and local address access
- SSDP message parsing
- Root device detection
- Packet data extraction
This class is used by SSDP components to handle incoming UDP packets containing discovery and advertisement messages, providing convenient access to both network information and message content.
Field Summary
Modifier and TypeFieldDescriptionprivate DatagramPacket/////////////////////////////////////////////private String/////////////////////////////////////////////byte[]Cached copy of the message bytes, filled in by the first read of the data.private long/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescriptionSSDPPacket(byte[] buf, int length) Wraps a received SSDP datagram without copying its bytes.Method Summary
All MethodsModifier and TypeMethodDescriptionReturns the CACHE-CONTROL header value.byte[]getData()Returns the message bytes, caching them on the first call.Returns the underlying datagram.getHost()Returns the HOST header value.Resolves the HOST header to an address.intReturns the advertised lease duration.Returns the local IP address that received this datagram.Returns the LOCATION header value.getMAN()Returns the MAN header value.intgetMX()Returns the MX header as a number of seconds.getNT()Returns the NT header value.getNTS()Returns the NTS header value.Returns the IP address this datagram was sent from.Returns the address this datagram was sent from.intReturns the UDP port this datagram was sent from.Returns the SERVER header value.getST()Returns the ST header value.longReturns when this datagram was received.getUSN()Returns the USN header value.booleanisAlive()Returns whether this is an ssdp:alive advertisement.booleanisByeBye()Returns whether this is an ssdp:byebye advertisement.booleanReturns whether this is a discover advertisement.booleanReturns whether NT, ST or USN identifies the root device.voidsetLocalAddress(String addr) Records the local IP address that received this datagram.voidsetTimeStamp(long value) Records when this datagram was received.toString()Renders the raw message text.
Field Details
dgmPacket
/////////////////////////////////////////////localAddr
/////////////////////////////////////////////timeStamp
private long timeStamp/////////////////////////////////////////////packetBytes
public byte[] packetBytesCached copy of the message bytes, filled in by the first read of the data.
Constructor Details
SSDPPacket
public SSDPPacket(byte[] buf, int length) Wraps a received SSDP datagram without copying its bytes.- Parameters:
buf- the buffer holding the received datagram, wrapped rather than copiedlength- how many bytes of buf this packet spans, in bytes
Method Details
getDatagramPacket
Returns the underlying datagram.- Returns:
- the wrapped DatagramPacket carrying this SSDP message
setLocalAddress
Records the local IP address that received this datagram.- Parameters:
addr- the local IP address that received the datagram
getLocalAddress
Returns the local IP address that received this datagram.- Returns:
- the local IP address that received this datagram
setTimeStamp
public void setTimeStamp(long value) Records when this datagram was received.- Parameters:
value- the receipt time in milliseconds since the epoch
getTimeStamp
public long getTimeStamp()Returns when this datagram was received.- Returns:
- when this datagram was received, in milliseconds since the epoch, or 0
getRemoteInetAddress
Returns the address this datagram was sent from.- Returns:
- the InetAddress this datagram was sent from
getRemoteAddress
Returns the IP address this datagram was sent from.- Returns:
- the IP address string this datagram was sent from
getRemotePort
public int getRemotePort()Returns the UDP port this datagram was sent from.- Returns:
- the UDP port number this datagram was sent from
getData
public byte[] getData()Returns the message bytes, caching them on the first call.- Returns:
- the UTF-8 message bytes of this datagram, cached in packetBytes once read
getHost
Returns the HOST header value.- Returns:
- the HOST header value, or an empty string if the message carries none
getCacheControl
Returns the CACHE-CONTROL header value.- Returns:
- the CACHE-CONTROL header value, or an empty string if the message carries none
getLocation
Returns the LOCATION header value.- Returns:
- the LOCATION header value, or an empty string if the message carries none
getMAN
Returns the MAN header value.- Returns:
- the MAN header value, or an empty string if the message carries none
getST
Returns the ST header value.- Returns:
- the ST header value, or an empty string if the message carries none
getNT
Returns the NT header value.- Returns:
- the NT header value, or an empty string if the message carries none
getNTS
Returns the NTS header value.- Returns:
- the NTS header value, or an empty string if the message carries none
getServer
Returns the SERVER header value.- Returns:
- the SERVER header value, or an empty string if the message carries none
getUSN
Returns the USN header value.- Returns:
- the USN header value, or an empty string if the message carries none
getMX
public int getMX()Returns the MX header as a number of seconds.- Returns:
- the MX header in seconds, or 0 if it is missing or unparseable
getHostInetAddress
Resolves the HOST header to an address.- Returns:
- the InetAddress named in the HOST header, or the loopback address if that header carries no port
isRootDevice
public boolean isRootDevice()Returns whether NT, ST or USN identifies the root device.- Returns:
- true if the NT, ST or USN header identifies this as the root device
isDiscover
public boolean isDiscover()Returns whether this is a discover advertisement.- Returns:
- true if the MAN header carries the discover advertisement
isAlive
public boolean isAlive()Returns whether this is an ssdp:alive advertisement.- Returns:
- true if the NTS header is ssdp:alive
isByeBye
public boolean isByeBye()Returns whether this is an ssdp:byebye advertisement.- Returns:
- true if the NTS header is ssdp:byebye
getLeaseTime
public int getLeaseTime()Returns the advertised lease duration.- Returns:
- the lease time in seconds, or 0 if the CACHE-CONTROL header carries no usable max-age
toString