Constructor and Description |
---|
UdpMessenger(int port)
Initiates UdpMessenger, binds it to the specified port and starts
listening.
|
UdpMessenger(int port,
java.net.InetAddress address)
Initiates UdpMessenger, binds it to the specified port and IP address and
starts listening.
|
Modifier and Type | Method and Description |
---|---|
void |
closeConnection()
Closes the socket and releases port.
|
int |
getBufferSize() |
int |
getPort() |
static int |
getSentPackets()
Returns number of packets sent since last creation of the instance of
UdpMessenger . |
void |
register(UdpListener listener)
Registers listener in the UdpMessenger so it will be notified via
UdpListener.notifyMessage(UdpMessage) when new message arrives. |
void |
run() |
void |
send(UdpMessage message)
Sends
UdpMessage . |
void |
setBufferSize(int bufferSize)
Sets message data buffer size to bufferSize.
|
void |
unregister(UdpListener listener)
Unregisters listener from UdpMessenger so it no longer will be notified.
|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public UdpMessenger(int port) throws java.net.SocketException, java.net.UnknownHostException
port
- - port to bind socket to.java.net.SocketException
- if the socket could not be opened, or the socket could not
bind to the specified local port.java.net.UnknownHostException
public UdpMessenger(int port, java.net.InetAddress address) throws java.net.SocketException
port
- - port to bind socket to.address
- - IP address to bind socket to.java.net.SocketException
- if the socket could not be opened, or the socket could not
bind to the specified local port.public int getPort()
public void setBufferSize(int bufferSize)
public int getBufferSize()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void closeConnection()
closeConnection
in interface Messenger
public void register(UdpListener listener)
UdpListener.notifyMessage(UdpMessage)
when new message arrives.register
in interface Messenger
listener
- - UdpListener
to register.public void unregister(UdpListener listener)
unregister
in interface Messenger
listener
- - UdpListener
to unregisterpublic static int getSentPackets()
UdpMessenger
. For debug/testing purposes only.public void send(UdpMessage message) throws java.io.IOException
UdpMessage
.send
in interface Messenger
message
- - UdpMessage
to send.java.io.IOException
- when sending of the message fails