com.kuka.comm.net
Class UdpServer

java.lang.Object
  extended by com.kuka.comm.AbstractServer
      extended by com.kuka.comm.AbstractThreadedServer
          extended by com.kuka.comm.net.UdpServer
All Implemented Interfaces:
Server

public final class UdpServer
extends AbstractThreadedServer

The UdpServer class creates a new UDP server for use with the KUKA Navigation Communication Framework.

After instantiation of this class, it will listening to a specified port for new incoming UdpConnection requests until its stop() method will be called. This listening is a blocking operation. Therefore this UdpServer will be started as an own thread by calling its start() method. The incoming datagram packets are forwarded to the corresponding connection based on the sender of the packet. If no connection accepts this sender, a new connection will be created and passed to the connection handler, and, if accepted, will receive the packet.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.kuka.comm.AbstractServer
AbstractServer.ConnectionConsumer
 
Constructor Summary
UdpServer(InetSocketAddress serverAddress, Encoder<Object,ByteBuffer> enc, Decoder<ByteBuffer,Object> dec)
          Constructor for UdpServer with defined port and IPAddress.
UdpServer(InetSocketAddress serverAddress, UdpConnectionHandler handler)
          Constructor for UdpServer with defined port and IPAddress.
UdpServer(int port, Encoder<Object,ByteBuffer> enc, Decoder<ByteBuffer,Object> dec)
          Constructor for UdpServer with defined port.
UdpServer(int port, UdpConnectionHandler handler)
          Constructor for UdpServer with defined port.
 
Method Summary
 InetAddress getAddress()
          Returns the server address.
 int getPort()
          Returns the server port.
 int getReceiveBufferSize()
          Returns the receiving buffer size.
 UdpConnectionHandler getUdpConnHandler()
          Returns the UDP connection factory.
protected  void serverThread()
          Implement the server thread!
 void setReceiveBufferSize(int bufferSize)
          Sets the receiving buffer size to the given value.
 void start()
          Starts the server as a separate thread.
 void stop()
          Stops the server closes all created connections listed in its internal list of connections.
 
Methods inherited from class com.kuka.comm.AbstractThreadedServer
isRunning, isStopRequested, isThreadAlive, setStopRequested
 
Methods inherited from class com.kuka.comm.AbstractServer
addConnection, addServerListener, closeAllConnections, countConnections, fireAcceptedConnection, fireIncomingConnection, fireRejectedConnection, forEachConnection, getConnections, hasConnections, removeConnection, removeServerListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UdpServer

public UdpServer(int port,
                 Encoder<Object,ByteBuffer> enc,
                 Decoder<ByteBuffer,Object> dec)
Constructor for UdpServer with defined port.

IPAddress is undefined and will be selected by kernel.

Parameters:
port - The listening port for UDPServer.
enc - The encoder.
dec - The decoder.

UdpServer

public UdpServer(InetSocketAddress serverAddress,
                 Encoder<Object,ByteBuffer> enc,
                 Decoder<ByteBuffer,Object> dec)
Constructor for UdpServer with defined port and IPAddress.

Parameters:
serverAddress - The IPAddress for UDPServer. Only packets with this IP will be accepted.
enc - The encoder.
dec - The decoder.

UdpServer

public UdpServer(int port,
                 UdpConnectionHandler handler)
Constructor for UdpServer with defined port.

IPAddress is undefined and will be selected by kernel.

Parameters:
port - The listening port for UDPServer.
handler - the connection handler

UdpServer

public UdpServer(InetSocketAddress serverAddress,
                 UdpConnectionHandler handler)
Constructor for UdpServer with defined port and IPAddress.

Parameters:
serverAddress - The IPAddress for UDPServer. Only packets with this IP will be accepted.
handler - the connection handler
Method Detail

setReceiveBufferSize

public void setReceiveBufferSize(int bufferSize)
Sets the receiving buffer size to the given value.
default size: 512 bytes

Parameters:
bufferSize - the receiving buffer size

getReceiveBufferSize

public int getReceiveBufferSize()
Returns the receiving buffer size.

Returns:
the receiving buffer size

getUdpConnHandler

public UdpConnectionHandler getUdpConnHandler()
Returns the UDP connection factory.

Returns:
the UDP connection factory

start

public void start()
Description copied from interface: Server
Starts the server as a separate thread.

Specified by:
start in interface Server
Overrides:
start in class AbstractThreadedServer

serverThread

protected void serverThread()
Description copied from class: AbstractThreadedServer
Implement the server thread!

Specified by:
serverThread in class AbstractThreadedServer

getAddress

public InetAddress getAddress()
Returns the server address.

Returns:
the server address

getPort

public int getPort()
Returns the server port.

Returns:
the server port

stop

public void stop()
Description copied from interface: Server
Stops the server closes all created connections listed in its internal list of connections.

Specified by:
stop in interface Server
Overrides:
stop in class AbstractThreadedServer


Copyright © 2019. All rights reserved.