DthingApi
Public Member Functions | Protected Member Functions | List of all members
java.net.Socket Class Reference

Public Member Functions

 Socket ()
 
 Socket (String dstName, int dstPort) throws UnknownHostException, IOException
 
 Socket (String dstName, int dstPort, InetAddress localAddress, int localPort) throws UnknownHostException, IOException
 
 Socket (InetAddress dstAddress, int dstPort) throws IOException
 
 Socket (InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort) throws IOException
 
synchronized void close () throws IOException
 
InetAddress getInetAddress ()
 
InputStream getInputStream () throws IOException
 
boolean getKeepAlive () throws SocketException
 
InetAddress getLocalAddress ()
 
int getLocalPort ()
 
OutputStream getOutputStream () throws IOException
 
int getPort ()
 
int getSoLinger () throws SocketException
 
synchronized int getReceiveBufferSize () throws SocketException
 
synchronized int getSendBufferSize () throws SocketException
 
synchronized int getSoTimeout () throws SocketException
 
boolean getTcpNoDelay () throws SocketException
 
void setKeepAlive (boolean keepAlive) throws SocketException
 
synchronized void setSendBufferSize (int size) throws SocketException
 
synchronized void setReceiveBufferSize (int size) throws SocketException
 
void setSoLinger (boolean on, int timeout) throws SocketException
 
synchronized void setSoTimeout (int timeout) throws SocketException
 
void setTcpNoDelay (boolean on) throws SocketException
 
String toString ()
 
void shutdownInput () throws IOException
 
void shutdownOutput () throws IOException
 
SocketAddress getLocalSocketAddress ()
 
SocketAddress getRemoteSocketAddress ()
 
boolean isBound ()
 
boolean isConnected ()
 
boolean isClosed ()
 
void bind (SocketAddress localAddr) throws IOException
 
void connect (SocketAddress remoteAddr) throws IOException
 
void connect (SocketAddress remoteAddr, int timeout) throws IOException
 
boolean isInputShutdown ()
 
boolean isOutputShutdown ()
 
void setReuseAddress (boolean reuse) throws SocketException
 
boolean getReuseAddress () throws SocketException
 
void setOOBInline (boolean oobinline) throws SocketException
 
boolean getOOBInline () throws SocketException
 
void setTrafficClass (int value) throws SocketException
 
int getTrafficClass () throws SocketException
 
void setPerformancePreferences (int connectionTime, int latency, int bandwidth)
 

Protected Member Functions

 Socket (SocketImpl impl) throws SocketException
 

Detailed Description

Provides a client-side TCP socket.

Constructor & Destructor Documentation

◆ Socket() [1/6]

java.net.Socket.Socket ( )
inline

Creates a new unconnected socket. When a SocketImplFactory is defined it creates the internal socket implementation, otherwise the default socket implementation will be used for this socket.

See also
SocketImplFactory
SocketImpl

◆ Socket() [2/6]

java.net.Socket.Socket ( String  dstName,
int  dstPort 
) throws UnknownHostException, IOException
inline

Creates a new streaming socket connected to the target host specified by the parameters

dstName

and

dstPort

. The socket is bound to any available port on the local host.

This implementation tries each IP address for the given hostname (in RFC 3484 order) until it either connects successfully or it exhausts the set.

Parameters
dstNamethe target host name or IP address to connect to.
dstPortthe port on the target host to connect to.
Exceptions
UnknownHostExceptionif the host name could not be resolved into an IP address.
IOExceptionif an error occurs while creating the socket.

◆ Socket() [3/6]

java.net.Socket.Socket ( String  dstName,
int  dstPort,
InetAddress  localAddress,
int  localPort 
) throws UnknownHostException, IOException
inline

Creates a new streaming socket connected to the target host specified by the parameters

dstName

and

dstPort

. On the local endpoint the socket is bound to the given address

localAddress

on port

localPort

. If

host

is

null

a loopback address is used to connect to.

This implementation tries each IP address for the given hostname (in RFC 3484 order) until it either connects successfully or it exhausts the set.

Parameters
dstNamethe target host name or IP address to connect to.
dstPortthe port on the target host to connect to.
localAddressthe address on the local host to bind to.
localPortthe port on the local host to bind to.
Exceptions
UnknownHostExceptionif the host name could not be resolved into an IP address.
IOExceptionif an error occurs while creating the socket.

◆ Socket() [4/6]

java.net.Socket.Socket ( InetAddress  dstAddress,
int  dstPort 
) throws IOException
inline

Creates a new streaming socket connected to the target host specified by the parameters

dstAddress

and

dstPort

. The socket is bound to any available port on the local host.

Parameters
dstAddressthe target host address to connect to.
dstPortthe port on the target host to connect to.
Exceptions
IOExceptionif an error occurs while creating the socket.

◆ Socket() [5/6]

java.net.Socket.Socket ( InetAddress  dstAddress,
int  dstPort,
InetAddress  localAddress,
int  localPort 
) throws IOException
inline

Creates a new streaming socket connected to the target host specified by the parameters

dstAddress

and

dstPort

. On the local endpoint the socket is bound to the given address

localAddress

on port

localPort

.

Parameters
dstAddressthe target host address to connect to.
dstPortthe port on the target host to connect to.
localAddressthe address on the local host to bind to.
localPortthe port on the local host to bind to.
Exceptions
IOExceptionif an error occurs while creating the socket.

◆ Socket() [6/6]

java.net.Socket.Socket ( SocketImpl  impl) throws SocketException
inlineprotected

Creates an unconnected socket with the given socket implementation.

Parameters
implthe socket implementation to be used.
Exceptions
SocketExceptionif an error occurs while creating the socket.

Member Function Documentation

◆ bind()

void java.net.Socket.bind ( SocketAddress  localAddr) throws IOException
inline

Binds this socket to the given local host address and port specified by the SocketAddress

localAddr

. If

localAddr

is set to

null

, this socket will be bound to an available local address on any free port.

Parameters
localAddrthe specific address and port on the local machine to bind to.
Exceptions
IllegalArgumentExceptionif the given SocketAddress is invalid or not supported.
IOExceptionif the socket is already bound or an error occurs while binding.

◆ close()

synchronized void java.net.Socket.close ( ) throws IOException
inline

Closes the socket. It is not possible to reconnect or rebind to this socket thereafter which means a new socket instance has to be created.

Exceptions
IOExceptionif an error occurs while closing the socket.

◆ connect() [1/2]

void java.net.Socket.connect ( SocketAddress  remoteAddr) throws IOException
inline

Connects this socket to the given remote host address and port specified by the SocketAddress

remoteAddr

.

Parameters
remoteAddrthe address and port of the remote host to connect to.
Exceptions
IllegalArgumentExceptionif the given SocketAddress is invalid or not supported.
IOExceptionif the socket is already connected or an error occurs while connecting.

◆ connect() [2/2]

void java.net.Socket.connect ( SocketAddress  remoteAddr,
int  timeout 
) throws IOException
inline

Connects this socket to the given remote host address and port specified by the SocketAddress

remoteAddr

with the specified timeout. The connecting method will block until the connection is established or an error occurred.

Parameters
remoteAddrthe address and port of the remote host to connect to.
timeoutthe timeout value in milliseconds or
0
for an infinite timeout.
Exceptions
IllegalArgumentExceptionif the given SocketAddress is invalid or not supported or the timeout value is negative.
IOExceptionif the socket is already connected or an error occurs while connecting.

◆ getInetAddress()

InetAddress java.net.Socket.getInetAddress ( )
inline

Returns the IP address of the target host this socket is connected to, or null if this socket is not yet connected.

◆ getInputStream()

InputStream java.net.Socket.getInputStream ( ) throws IOException
inline

Returns an input stream to read data from this socket.

Returns
the byte-oriented input stream.
Exceptions
IOExceptionif an error occurs while creating the input stream or the socket is in an invalid state.

◆ getKeepAlive()

boolean java.net.Socket.getKeepAlive ( ) throws SocketException
inline

Returns this socket's SocketOptions#SO_KEEPALIVE setting.

◆ getLocalAddress()

InetAddress java.net.Socket.getLocalAddress ( )
inline

Returns the local IP address this socket is bound to, or

InetAddress.ANY

if the socket is unbound.

◆ getLocalPort()

int java.net.Socket.getLocalPort ( )
inline

Returns the local port this socket is bound to, or -1 if the socket is unbound.

◆ getLocalSocketAddress()

SocketAddress java.net.Socket.getLocalSocketAddress ( )
inline

Returns the local address and port of this socket as a SocketAddress or null if the socket is unbound. This is useful on multihomed hosts.

◆ getOOBInline()

boolean java.net.Socket.getOOBInline ( ) throws SocketException
inline

Returns this socket's SocketOptions#SO_OOBINLINE setting.

◆ getOutputStream()

OutputStream java.net.Socket.getOutputStream ( ) throws IOException
inline

Returns an output stream to write data into this socket.

Returns
the byte-oriented output stream.
Exceptions
IOExceptionif an error occurs while creating the output stream or the socket is in an invalid state.

◆ getPort()

int java.net.Socket.getPort ( )
inline

Returns the port number of the target host this socket is connected to, or 0 if this socket is not yet connected.

◆ getReceiveBufferSize()

synchronized int java.net.Socket.getReceiveBufferSize ( ) throws SocketException
inline

Returns this socket's receive buffer size.

◆ getRemoteSocketAddress()

SocketAddress java.net.Socket.getRemoteSocketAddress ( )
inline

Returns the remote address and port of this socket as a

SocketAddress

or null if the socket is not connected.

Returns
the remote socket address and port.

◆ getReuseAddress()

boolean java.net.Socket.getReuseAddress ( ) throws SocketException
inline

Returns this socket's SocketOptions#SO_REUSEADDR setting.

◆ getSendBufferSize()

synchronized int java.net.Socket.getSendBufferSize ( ) throws SocketException
inline

Returns this socket's send buffer size.

◆ getSoLinger()

int java.net.Socket.getSoLinger ( ) throws SocketException
inline

Returns this socket's linger timeout in seconds, or -1 for no linger (i.e.

will return immediately).

◆ getSoTimeout()

synchronized int java.net.Socket.getSoTimeout ( ) throws SocketException
inline

Returns this socket's receive timeout.

◆ getTcpNoDelay()

boolean java.net.Socket.getTcpNoDelay ( ) throws SocketException
inline

Returns this socket's

SocketOptions#TCP_NODELAY

setting.

◆ getTrafficClass()

int java.net.Socket.getTrafficClass ( ) throws SocketException
inline

Returns this socket's {

See also
SocketOptions::IP_TOS} setting.

◆ isBound()

boolean java.net.Socket.isBound ( )
inline

Returns whether this socket is bound to a local address and port.

Returns
true
if the socket is bound to a local address,
false
otherwise.

◆ isClosed()

boolean java.net.Socket.isClosed ( )
inline

Returns whether this socket is closed.

Returns
true
if the socket is closed,
false
otherwise.

◆ isConnected()

boolean java.net.Socket.isConnected ( )
inline

Returns whether this socket is connected to a remote host.

Returns
true
if the socket is connected,
false
otherwise.

◆ isInputShutdown()

boolean java.net.Socket.isInputShutdown ( )
inline

Returns whether the incoming channel of the socket has already been closed.

Returns
true
if reading from this socket is not possible anymore,
false
otherwise.

◆ isOutputShutdown()

boolean java.net.Socket.isOutputShutdown ( )
inline

Returns whether the outgoing channel of the socket has already been closed.

Returns
true
if writing to this socket is not possible anymore,
false
otherwise.

◆ setKeepAlive()

void java.net.Socket.setKeepAlive ( boolean  keepAlive) throws SocketException
inline

Sets this socket's SocketOptions#SO_KEEPALIVE option.

◆ setOOBInline()

void java.net.Socket.setOOBInline ( boolean  oobinline) throws SocketException
inline

Sets this socket's SocketOptions#SO_OOBINLINE option.

◆ setPerformancePreferences()

void java.net.Socket.setPerformancePreferences ( int  connectionTime,
int  latency,
int  bandwidth 
)
inline

Sets performance preferences for connectionTime, latency and bandwidth.

This method does currently nothing.

Parameters
connectionTimethe value representing the importance of a short connecting time.
latencythe value representing the importance of low latency.
bandwidththe value representing the importance of high bandwidth.

◆ setReceiveBufferSize()

synchronized void java.net.Socket.setReceiveBufferSize ( int  size) throws SocketException
inline

Sets this socket's receive buffer size.

◆ setReuseAddress()

void java.net.Socket.setReuseAddress ( boolean  reuse) throws SocketException
inline

Sets this socket's SocketOptions#SO_REUSEADDR option.

◆ setSendBufferSize()

synchronized void java.net.Socket.setSendBufferSize ( int  size) throws SocketException
inline

Sets this socket's send buffer size.

◆ setSoLinger()

void java.net.Socket.setSoLinger ( boolean  on,
int  timeout 
) throws SocketException
inline

Sets this socket's linger timeout in seconds. If

on

is false,

timeout

is irrelevant.

◆ setSoTimeout()

synchronized void java.net.Socket.setSoTimeout ( int  timeout) throws SocketException
inline

Sets this socket's read timeout in milliseconds. Use 0 for no timeout. To take effect, this option must be set before the blocking method was called.

◆ setTcpNoDelay()

void java.net.Socket.setTcpNoDelay ( boolean  on) throws SocketException
inline

Sets this socket's SocketOptions#TCP_NODELAY option.

◆ setTrafficClass()

void java.net.Socket.setTrafficClass ( int  value) throws SocketException
inline

Sets this socket's SocketOptions#IP_TOS value for every packet sent by this socket.

◆ shutdownInput()

void java.net.Socket.shutdownInput ( ) throws IOException
inline

Closes the input stream of this socket. Any further data sent to this socket will be discarded. Reading from this socket after this method has been called will return the value

EOF

.

Exceptions
IOExceptionif an error occurs while closing the socket input stream.
SocketExceptionif the input stream is already closed.

◆ shutdownOutput()

void java.net.Socket.shutdownOutput ( ) throws IOException
inline

Closes the output stream of this socket. All buffered data will be sent followed by the termination sequence. Writing to the closed output stream will cause an

IOException

.

Exceptions
IOExceptionif an error occurs while closing the socket output stream.
SocketExceptionif the output stream is already closed.

◆ toString()

String java.net.Socket.toString ( )
inline

Returns a

String

containing a concise, human-readable description of the socket.

Returns
the textual representation of this socket.

The documentation for this class was generated from the following file: