Class TcpLayer
- java.lang.Object
-
- org.openmuc.jdlms.transportlayer.client.TcpLayer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,TransportLayer
,StreamAccessor
public class TcpLayer extends java.lang.Object implements TransportLayer
Class to handle all outgoing and incoming TCP packets over one TCP connection.
-
-
Constructor Summary
Constructors Constructor Description TcpLayer(TcpSettings settings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Will close the TCP connection to the server if its still open and free any resources of this connection.java.io.DataInputStream
getInputStream()
Returns the input stream for this stream accessor.java.io.DataOutputStream
getOutpuStream()
Returns the output stream for this stream accessor.boolean
isClosed()
Status of the connection/transport layer.void
open()
Opens the physical layer.void
setTimeout(int timeout)
Enable/disable TIMEOUT with the specified timeout, in milliseconds.
-
-
-
Constructor Detail
-
TcpLayer
public TcpLayer(TcpSettings settings)
-
-
Method Detail
-
setTimeout
public void setTimeout(int timeout) throws java.io.IOException
Description copied from interface:StreamAccessor
Enable/disable TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on theInputStream
m associated with this StreamAcessor will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be> 0
. A timeout of zero is interpreted as an infinite timeout.- Specified by:
setTimeout
in interfaceStreamAccessor
- Parameters:
timeout
- the specified timeout, in milliseconds.- Throws:
java.io.IOException
- if there is an error in the underlying protocol, such as a TCP error.
-
getInputStream
public java.io.DataInputStream getInputStream()
Description copied from interface:StreamAccessor
Returns the input stream for this stream accessor.- Specified by:
getInputStream
in interfaceStreamAccessor
- Returns:
- the input stream.
-
isClosed
public boolean isClosed()
Description copied from interface:TransportLayer
Status of the connection/transport layer.- Specified by:
isClosed
in interfaceTransportLayer
- Returns:
true
if the connection is closesfalse
otherwhise.
-
getOutpuStream
public java.io.DataOutputStream getOutpuStream()
Description copied from interface:StreamAccessor
Returns the output stream for this stream accessor.- Specified by:
getOutpuStream
in interfaceStreamAccessor
- Returns:
- the output stream.
-
open
public void open() throws java.io.IOException
Description copied from interface:TransportLayer
Opens the physical layer.- Specified by:
open
in interfaceTransportLayer
- Throws:
java.io.IOException
- if an error occurred opening the stream.
-
close
public void close() throws java.io.IOException
Will close the TCP connection to the server if its still open and free any resources of this connection.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceStreamAccessor
- Throws:
java.io.IOException
-
-