|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.kuka.comm.AbstractConnection
com.kuka.comm.net.NetConnection
com.kuka.comm.net.TcpConnection
public final class TcpConnection
A connection instantiation for TCP over JavaIO.
| Field Summary |
|---|
| Fields inherited from class com.kuka.comm.net.NetConnection |
|---|
_inputBuffer, _localAddress, _outputBuffer, _remoteAddress |
| Constructor Summary | |
|---|---|
TcpConnection(InetSocketAddress remoteAddress)
Constructor using InetSocketAddress as connection target. |
|
TcpConnection(InetSocketAddress remoteAddress,
InetSocketAddress localAddress)
Constructor using first InetSocketAddress as connection target and a second one as its own address/port
values.. |
|
TcpConnection(Socket socket)
Constructor for a connection using an already existing socket. |
|
| Method Summary | |
|---|---|
void |
connect()
Connects (or initiates) the connection asynchronously. |
void |
disconnect()
Disconnects (or closes) the connection asynchronously. |
TcpConnection |
enableLinger(boolean enable,
int timeout)
En-/Disable linger option for socket. |
TcpConnectionStatistics |
getStatistics()
Returns general connection statistics about this connection. |
boolean |
isAbleToReceive()
Returns true if the current state of the connection allows to receive messages. |
boolean |
isAbleToSend()
Returns true if the current state of the connection allows to send messages. |
boolean |
isConnected()
Returns true of the connection is working as expected. |
boolean |
isConnectionless()
Checks if the underlying connection type implements a connectionless communication method. |
boolean |
isTcpNoDelay()
Method to retrieve the current status for the TCP sending parameter. |
TcpConnection |
keepConnectionAlive(boolean keepAlive)
Option to en-/disable the sending to a keep alive packet after two hours without incoming data. |
void |
send(Object msg)
This method will send the message. |
TcpConnection |
setTcpNoDelay(boolean tcpNoDelay)
TCP specific setting. |
TcpConnection |
setTimeout(int timeout)
Sets the timeout in milliseconds, which determines the time the Socket got block during reading. |
String |
toString()
|
| Methods inherited from class com.kuka.comm.net.NetConnection |
|---|
getDecoder, getEncoder, getLocalAddress, getRemoteAddress, hasDecoder, hasEncoder, setDecoder, setEncoder, setInputBufferSize, setOutputBufferSize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TcpConnection(InetSocketAddress remoteAddress)
InetSocketAddress as connection target.
remoteAddress - The connection target as InetSocketAddress
public TcpConnection(InetSocketAddress remoteAddress,
InetSocketAddress localAddress)
InetSocketAddress as connection target and a second one as its own address/port
values..
remoteAddress - The remote target ip address and port as InetSocketAddress.localAddress - The local address and port for this connection as InetSocketAddress.public TcpConnection(Socket socket)
socket - The Socket to use with this connection.| Method Detail |
|---|
public void send(Object msg)
throws ConnectionException
Connection
The message type is Object to ensure that all kinds of messages can be send by the same interface. Type
safety is ensured by the used Encoder, that must be able to handle the actual message type (i.e.
serialize it correctly), otherwise the message will not be send.
msg - The message to be send.
ConnectionException - if sending failspublic void connect()
ConnectionConnection.isConnected(). Only a connected connection can be used for sending or receiving messages.
public void disconnect()
ConnectionConnection.isConnected(). A disconnected connection cannot be used for sending and will not receive any messages. A
disconnected connection can be reconnected by calling Connection.connect().
disconnect in interface Connectiondisconnect in class AbstractConnectionpublic TcpConnection setTcpNoDelay(boolean tcpNoDelay)
Otherwise it would wait until TCP-packet size is reached to reduce communication overhead.
tcpNoDelay - Boolean value. true disables Nagle's algorithm, while false will enable it.
public boolean isTcpNoDelay()
true if packets should be send even if TCP dataframe is not completely full (see Nagle's
algorithm for further information), false otherwisepublic TcpConnection setTimeout(int timeout)
Socket got block during reading. Any
value different from zero will block the socket only for this amount of time. If reading is unable to finish
successfully in given time, an SocketTimeoutException will be raised. The socket could be used again for
other operations (e.g. writing, Socket.close(), ...).
If a timeout has occured, the a connection listener's
ConnectionListener.onConnectionTimeout(com.kuka.comm.Connection) method will be called. The
listener can be added with AbstractConnection.addConnectionListener(com.kuka.comm.ConnectionListener). The user can then
close the connection manually.
timeout - Integer value stating the amount of milliseconds. A value of zero disables timeout.
public TcpConnection keepConnectionAlive(boolean keepAlive)
keepAlive - true enables the option, false disables it.
public TcpConnection enableLinger(boolean enable,
int timeout)
enable - true enables linger option, false disables linger.timeout - The amount of time to wait after a closed connection for remaining data.
public TcpConnectionStatistics getStatistics()
Connection
getStatistics in interface ConnectiongetStatistics in class NetConnectionpublic boolean isConnected()
ConnectionConnection.isAbleToSend() and
Connection.isAbleToReceive() can be used to further check if sending or receiving of messages is possible.
public boolean isAbleToReceive()
Connectiontrue if the current state of the connection allows to receive messages. For this, the
connection at least must be connected (see also Connection.isConnected()) and an encoder must have been set. The
method Connection.hasDecoder() can be used to check if a Decoder has been set.
isAbleToReceive in interface ConnectionisAbleToReceive in class AbstractConnectiontrue, if the connection can be used to receive messagespublic boolean isAbleToSend()
ConnectionConnection.isConnected()) and an Encoder must have been set in the concrete
class implementing the Connection interface. The method Connection.hasEncoder() can be used to check
if an Encoder has been set.
isAbleToSend in interface ConnectionisAbleToSend in class AbstractConnectionpublic boolean isConnectionless()
Connectiontrue. A connectionless connection will behave in a slightly different way than a
connection-oriented connection, i.e. the connection will not be disconnected if the remote end point stops
working properly. Further, the method Connection.isConnected() only ensures that the local setup is working
properly but does not give any guarantees that the remote end point is working properly. Likewise,
Connection.isAbleToSend() will refer to the state of the local setup, but it will not guarantee that the message
will also be received or that the remote end point is even existing.
true, if the connection implements a connectionless communication method, false
otherwisepublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||