R
- the type to receive over UDPpublic class UDPListener<R extends java.io.Serializable>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UDPListener.UDPMessage<R extends java.io.Serializable>
UDP Packets received will be broken down into these messages detailing
where the packet came from and what was in it.
|
Constructor and Description |
---|
UDPListener(int port)
A Listener created with this constructor will fail when an unexpected
type is received.
|
UDPListener(int port,
java.lang.Class<R> receivingClass)
A Listener created with this constructor will ignore any unexpected types
received.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the listener
|
UDPListener.UDPMessage<R> |
receive()
Receives a message over UDP.
|
UDPListener.UDPMessage<R> |
receive(long timeout,
java.util.concurrent.TimeUnit unit)
Receives a message over UDP.
|
boolean |
receiveWillBlock()
Returns whether a call to receive() will block to wait on new data or not
|
public UDPListener(int port) throws java.net.SocketException
port
- the port to listen onjava.net.SocketException
- if the listener could not be openedpublic UDPListener(int port, java.lang.Class<R> receivingClass) throws java.net.SocketException
port
- the port to listen onreceivingClass
- the class of object that will be received by this manager.
Required to circumvent Java generics type erasure.java.net.SocketException
- if the listener could not be openedpublic void close()
public UDPListener.UDPMessage<R> receive() throws java.lang.InterruptedException
java.lang.InterruptedException
- if the waiting was interruptedpublic UDPListener.UDPMessage<R> receive(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
timeout
- the amount of time before timeoutunit
- the unit of timejava.lang.InterruptedException
- if the waiting was interruptedpublic boolean receiveWillBlock()