Class PTCPSocket
java.lang.Object
java.net.Socket
ecmwf.common.transport.ptcp.psocket.PTCPSocket
-
Constructor Summary
ConstructorsConstructorDescriptionPTCPSocket
(int num) Instantiates a new PTCP socket.PTCPSocket
(String host, int port, int num) Instantiates a new PTCP socket.PTCPSocket
(String host, int port, InetAddress localAddr, int localPort, int num) Instantiates a new PTCP socket.PTCPSocket
(InetAddress address, int port, int num) Instantiates a new PTCP socket.PTCPSocket
(InetAddress address, int port, InetAddress localAddr, int localPort, int num) Instantiates a new PTCP socket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the socket.void
close()
Close.Returns the address to which the socket is connected.Returns an input stream for this socket.boolean
Tests if SO_KEEPALIVE is enabled.Gets the local address to which the socket is bound.int
Returns the local port to which this socket is bound.Returns an output stream for this socket.int
getPort()
Returns the remote port to which this socket is connected.int
Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.int
Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.int
Returns setting for SO_LINGER. -1 returns implies that the option is disabled.int
Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).boolean
Tests if TCP_NODELAY is enabled.boolean
Returns the connection state of the socket.void
setKeepAlive
(boolean on) Enable/disable SO_KEEPALIVE.void
setReceiveBufferSize
(int size) Sets the SO_RCVBUF option to the specified value for this Socket.void
setSendBufferSize
(int size) Sets the SO_SNDBUF option to the specified value for this Socket.void
setSoLinger
(boolean on, int linger) Enable/disable SO_LINGER with the specified linger time in seconds.void
setSoTimeout
(int timeout) Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.void
setTcpNoDelay
(boolean on) Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).void
Places the input stream for this socket at "end of stream".void
Disables the output stream for this socket.toString()
Converts this socket to a String.Methods inherited from class java.net.Socket
bind, connect, connect, getChannel, getLocalSocketAddress, getOOBInline, getOption, getRemoteSocketAddress, getReuseAddress, getTrafficClass, isBound, isClosed, isInputShutdown, isOutputShutdown, sendUrgentData, setOOBInline, setOption, setPerformancePreferences, setReuseAddress, setSocketImplFactory, setTrafficClass, supportedOptions
-
Constructor Details
-
PTCPSocket
public PTCPSocket(int num) Instantiates a new PTCP socket.- Parameters:
num
- the num
-
PTCPSocket
Instantiates a new PTCP socket.- Parameters:
host
- the hostport
- the portnum
- the num- Throws:
UnknownHostException
- the unknown host exceptionIOException
- Signals that an I/O exception has occurred.
-
PTCPSocket
Instantiates a new PTCP socket.- Parameters:
address
- the addressport
- the portnum
- the num- Throws:
UnknownHostException
- the unknown host exceptionIOException
- Signals that an I/O exception has occurred.
-
PTCPSocket
public PTCPSocket(String host, int port, InetAddress localAddr, int localPort, int num) throws UnknownHostException, IOException Instantiates a new PTCP socket.- Parameters:
host
- the hostport
- the portlocalAddr
- the local addrlocalPort
- the local portnum
- the num- Throws:
UnknownHostException
- the unknown host exceptionIOException
- Signals that an I/O exception has occurred.
-
PTCPSocket
public PTCPSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int num) throws UnknownHostException, IOException Instantiates a new PTCP socket.- Parameters:
address
- the addressport
- the portlocalAddr
- the local addrlocalPort
- the local portnum
- the num- Throws:
UnknownHostException
- the unknown host exceptionIOException
- Signals that an I/O exception has occurred.
-
-
Method Details
-
getInetAddress
Returns the address to which the socket is connected.- Overrides:
getInetAddress
in classSocket
-
getInputStream
Returns an input stream for this socket.- Overrides:
getInputStream
in classSocket
- Throws:
IOException
-
setKeepAlive
Enable/disable SO_KEEPALIVE.- Overrides:
setKeepAlive
in classSocket
- Throws:
SocketException
-
getKeepAlive
Tests if SO_KEEPALIVE is enabled.- Overrides:
getKeepAlive
in classSocket
- Throws:
SocketException
-
getLocalAddress
Gets the local address to which the socket is bound.- Overrides:
getLocalAddress
in classSocket
-
getLocalPort
public int getLocalPort()Returns the local port to which this socket is bound.- Overrides:
getLocalPort
in classSocket
-
getOutputStream
Returns an output stream for this socket.- Overrides:
getOutputStream
in classSocket
- Throws:
IOException
-
getPort
-
setReceiveBufferSize
Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers. Increasing buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data. For UDP, this sets the maximum size of a packet that may be sent on this Socket. Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize().- Overrides:
setReceiveBufferSize
in classSocket
- Throws:
SocketException
-
getReceiveBufferSize
Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.- Overrides:
getReceiveBufferSize
in classSocket
- Throws:
SocketException
-
setSendBufferSize
Sets the SO_SNDBUF option to the specified value for this Socket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers. Increasing buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data. For UDP, this sets the maximum size of a packet that may be sent on this Socket. Because SO_SNDBUF is a hint, applications that want to verify what size the buffers were set to should call getSendBufferSize(). Parameters:- Overrides:
setSendBufferSize
in classSocket
- Throws:
SocketException
-
getSendBufferSize
Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.- Overrides:
getSendBufferSize
in classSocket
- Throws:
SocketException
-
setSoLinger
Enable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.- Overrides:
setSoLinger
in classSocket
- Throws:
SocketException
-
getSoLinger
Returns setting for SO_LINGER. -1 returns implies that the option is disabled. The setting only affects socket close.- Overrides:
getSoLinger
in classSocket
- Throws:
SocketException
-
setSoTimeout
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.io.InterruptedIOException 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.- Overrides:
setSoTimeout
in classSocket
- Throws:
SocketException
-
getSoTimeout
Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).- Overrides:
getSoTimeout
in classSocket
- Throws:
SocketException
-
getTcpNoDelay
Tests if TCP_NODELAY is enabled.- Overrides:
getTcpNoDelay
in classSocket
- Throws:
SocketException
-
setTcpNoDelay
Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).- Overrides:
setTcpNoDelay
in classSocket
- Throws:
SocketException
-
addSocket
-
shutdownInput
Places the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded. If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.- Overrides:
shutdownInput
in classSocket
- Throws:
IOException
-
shutdownOutput
Disables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.- Overrides:
shutdownOutput
in classSocket
- Throws:
IOException
-
toString
-
isConnected
public boolean isConnected()Returns the connection state of the socket.- Overrides:
isConnected
in classSocket
-
close
Close.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classSocket
- Throws:
IOException
-