|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService SK.gnome.dwarf.thread.ThreadService SK.gnome.dwarf.tcpip.Listener SK.gnome.dwarf.tcpip.UDPListener
Service for receiving client datagrams.
It listenes on a specified port and address and passes the received datagrams to
the TCPIPServer
for further processing.
Field Summary | |
protected java.net.InetAddress |
connectAddress
The internet address to connect to. |
protected int |
connectPort
The network port to connect to. |
protected int |
packetSize
The size of the datagram packet in bytes. |
protected java.net.DatagramSocket |
socket
The datagram socket. |
Fields inherited from class SK.gnome.dwarf.tcpip.Listener |
address, allowedHosts, deniedHosts, port |
Fields inherited from class SK.gnome.dwarf.thread.ThreadService |
daemon, thread |
Fields inherited from class SK.gnome.dwarf.GenericService |
initParameters, parent |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
UDPListener(java.lang.String name)
Creates a new UDPListener. |
Method Summary | |
protected boolean |
enableThread()
Enables or disables the service thread. |
protected void |
finish()
Waits for the thread to complete. |
protected java.net.DatagramPacket |
getDatagramPacket()
Returns the datagram packet. |
protected java.net.DatagramSocket |
getDatagramSocket()
Returns the datagram socket. |
void |
init(Server parent)
Initializes the service. |
protected void |
loop()
Performs the listening operation. |
void |
setConnectAddress(java.net.InetAddress address)
Sets the internet address to connect to. |
void |
setConnectPort(int port)
Sets the port to connect to. |
void |
setPacketSize(int size)
Sets the datagram packet size. |
Methods inherited from class SK.gnome.dwarf.tcpip.Listener |
acceptHost, setAddress, setAllowedHosts, setDeniedHosts, setPort |
Methods inherited from class SK.gnome.dwarf.thread.ThreadService |
run, setDaemon, shutdown, start, stop |
Methods inherited from class SK.gnome.dwarf.GenericService |
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.net.InetAddress connectAddress
setConnectAddress(InetAddress)
protected int connectPort
setConnectPort(int)
protected int packetSize
Default value: TCPIPConstants.TCPIP_DEFAULT_UDP_PACKET_SIZE
setPacketSize(int)
protected java.net.DatagramSocket socket
init(Server)
Constructor Detail |
public UDPListener(java.lang.String name)
Method Detail |
public void setConnectAddress(java.net.InetAddress address)
address
- the internet addressListener.address
public void setConnectPort(int port)
port
- the portListener.port
public void setPacketSize(int size)
size
- the packet size in bytes
java.lang.IllegalArgumentException
- if the size exceeds the
TCPIPConstants.TCPIP_MAX_UDP_PACKET_SIZE
limitpacketSize
public void init(Server parent) throws ServiceException
Sets the socket
field to value returned by the getDatagramSocket()
method.
This method requires that the parent server is an instance of the TCPIPServer
class.
init
in interface Service
init
in class GenericService
ServiceException
protected void finish()
It closes the socket
, which causes an interruption of the blocked listening
thread, so it can finish gracefully.
finish
in class ThreadService
protected boolean enableThread()
This method always returns true, so the new listening thread is always started.
enableThread
in class ThreadService
protected void loop()
Listenes on a specified port and address via the socket
. The datagram packet
for receiving client data is obtained from the getDatagramPacket()
method. If a
new client datagram is detected, the listener first checks whether the datagram should be
accepted by invoking the inherited Listener.acceptHost(InetAddress)
method with
the address of the received datagram. If the result is true, it passes the datagram
to the parent server by calling its TCPIPServer.enqueue(Object)
method. In the case
the listener will not accept the datagram, it is discarded and a warning message is written
to the log.
loop
in class ThreadService
protected java.net.DatagramSocket getDatagramSocket() throws ServiceException
Returns the socket for listening. The returned socket will be bound to the Listener.port
.
If the Listener.address
field is null, the socket will use all available addresses.
If the connectAddress
and connectPort
is not null, the socket will be
connected to the given address and port before returned from this method.
ServiceException
protected java.net.DatagramPacket getDatagramPacket()
Returns the datagram packet for receiving client data. The packet size must not
exceed the TCPIPConstants.TCPIP_MAX_UDP_PACKET_SIZE
limit. This method returns
a new java.net.DatagramPacket object with size equal to the packetSize
.
It can be overriden to implement the packet caching/reusing for a high-performance
streaming servers, for example.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |