com.kuka.comm.net
Class TcpServer

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

public final class TcpServer
extends AbstractThreadedServer

The TcpServer class creates a new TCP server for use with the KUKA Navigation Communication Framework.

After instantiation of this class, it will listening to a specified port for new incoming TcpConnection requests until its stop() method will be called. This listening is a blocking operation. Therefore this TcpServer will be started as an own thread by calling its start() method.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.kuka.comm.AbstractServer
AbstractServer.ConnectionConsumer
 
Constructor Summary
TcpServer(InetSocketAddress serverAddress, Encoder<Object,ByteBuffer> enc, Decoder<ByteBuffer,Object> dec)
          Constructor to setup an new TCP server with a given InetSocketAddress to listen on.
TcpServer(InetSocketAddress serverAddress, TcpConnectionHandler handler)
          Constructor to setup an new TCP server with a given InetSocketAddress to listen on.
TcpServer(int port, Encoder<Object,ByteBuffer> enc, Decoder<ByteBuffer,Object> dec)
          Constructor to setup an new TCP server with a given port to listen on.
TcpServer(int port, TcpConnectionHandler handler)
          Constructor to setup an new TCP server with a given port to listen on.
 
Method Summary
 InetAddress getAddress()
          Returns the server address.
 int getPort()
          Returns the server port.
 TcpConnectionHandler getTcpConnHandler()
          Get method for the factory method, which creates new TcpConnections upon incoming connections.
protected  void serverThread()
          Implement the server thread!
 void start()
          Starts the server as a separate thread.
 void stop()
          Method to stop the TcpServer by closing the ServerSocket.
 
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

TcpServer

public TcpServer(int port,
                 Encoder<Object,ByteBuffer> enc,
                 Decoder<ByteBuffer,Object> dec)
Constructor to setup an new TCP server with a given port to listen on.

Parameters:
port - The port as Integer to listen for new connections.
enc - The encoder to encode messages.
dec - the decoder to decoder messages.

TcpServer

public TcpServer(InetSocketAddress serverAddress,
                 Encoder<Object,ByteBuffer> enc,
                 Decoder<ByteBuffer,Object> dec)
Constructor to setup an new TCP server with a given InetSocketAddress to listen on.

Parameters:
serverAddress - The InetSocketAddress which specifies the host address and port.
enc - The encoder to encode messages.
dec - the decoder to decoder messages.

TcpServer

public TcpServer(int port,
                 TcpConnectionHandler handler)
Constructor to setup an new TCP server with a given port to listen on.

Parameters:
port - The port as Integer to listen for new connections.
handler - A handler creating and configuring incoming connections.

TcpServer

public TcpServer(InetSocketAddress serverAddress,
                 TcpConnectionHandler handler)
Constructor to setup an new TCP server with a given InetSocketAddress to listen on.

Parameters:
serverAddress - The InetSocketAddress which specifies the host address and port.
handler - A handler creating and configuring incoming connections.
Method Detail

getTcpConnHandler

public TcpConnectionHandler getTcpConnHandler()
Get method for the factory method, which creates new TcpConnections upon incoming connections.

Returns:
The TcpConnectionConfigurator which creates new TcpConnections.

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

stop

public void stop()
Method to stop the TcpServer by closing the ServerSocket. Its reference will be deleted upon next garbage collection.

Specified by:
stop in interface Server
Overrides:
stop 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


Copyright © 2019. All rights reserved.