Class TcpTransport
java.lang.Object
com.trdp.network.TcpTransport
- All Implemented Interfaces:
AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionTcpTransport(String host, int port) TcpTransport(String host, int port, InetAddress bindAddress, int trafficClass) Creates a TCP transport with custom socket options. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanisClosed()intreceive(byte[] buffer, int timeoutMs) Reads a complete TRDP MD frame from the TCP stream.voidsend(byte[] data) voidsetSoTimeout(int timeoutMs)
-
Constructor Details
-
TcpTransport
- Throws:
IOException
-
TcpTransport
public TcpTransport(String host, int port, InetAddress bindAddress, int trafficClass) throws IOException Creates a TCP transport with custom socket options.- Parameters:
host- the remote host to connect toport- the remote port to connect tobindAddress- the local address to bind to, ornullfor any local addresstrafficClass- the IP traffic class byte (useUdpTransport.qosToTrafficClass(int)to convert from QoS), or 0 to leave at OS default- Throws:
IOException- if connection fails
-
-
Method Details
-
send
- Throws:
IOException
-
receive
Reads a complete TRDP MD frame from the TCP stream. Reads the fixed-size MD header first to determine payload length, then reads the exact payload.- Parameters:
buffer- Buffer to receive the frame (must be at leastTrdpConstants.TRDP_MD_HEADER_SIZE+TrdpConstants.TRDP_MAX_MD_DATA_SIZEbytes).timeoutMs- Socket timeout in milliseconds.- Returns:
- Total bytes read (header + payload), 0 on timeout, -1 on EOF.
- Throws:
IOException
-
getInputStream
- Throws:
IOException
-
setSoTimeout
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
isClosed
public boolean isClosed()
-