Socket (Java Platform SE 7 ) (original) (raw)

Modifier and Type

Method and Description

void

**[bind](../../java/net/Socket.html#bind%28java.net.SocketAddress%29)**([SocketAddress](../../java/net/SocketAddress.html "class in java.net") bindpoint)

Binds the socket to a local address.

void

**[close](../../java/net/Socket.html#close%28%29)**()

Closes this socket.

void

**[connect](../../java/net/Socket.html#connect%28java.net.SocketAddress%29)**([SocketAddress](../../java/net/SocketAddress.html "class in java.net") endpoint)

Connects this socket to the server.

void

**[connect](../../java/net/Socket.html#connect%28java.net.SocketAddress,%20int%29)**([SocketAddress](../../java/net/SocketAddress.html "class in java.net") endpoint, int timeout)

Connects this socket to the server with a specified timeout value.

[SocketChannel](../../java/nio/channels/SocketChannel.html "class in java.nio.channels")

**[getChannel](../../java/net/Socket.html#getChannel%28%29)**()

Returns the unique SocketChannel object associated with this socket, if any.

[InetAddress](../../java/net/InetAddress.html "class in java.net")

**[getInetAddress](../../java/net/Socket.html#getInetAddress%28%29)**()

Returns the address to which the socket is connected.

[InputStream](../../java/io/InputStream.html "class in java.io")

**[getInputStream](../../java/net/Socket.html#getInputStream%28%29)**()

Returns an input stream for this socket.

boolean

**[getKeepAlive](../../java/net/Socket.html#getKeepAlive%28%29)**()

Tests if SO_KEEPALIVE is enabled.

[InetAddress](../../java/net/InetAddress.html "class in java.net")

**[getLocalAddress](../../java/net/Socket.html#getLocalAddress%28%29)**()

Gets the local address to which the socket is bound.

int

**[getLocalPort](../../java/net/Socket.html#getLocalPort%28%29)**()

Returns the local port number to which this socket is bound.

[SocketAddress](../../java/net/SocketAddress.html "class in java.net")

**[getLocalSocketAddress](../../java/net/Socket.html#getLocalSocketAddress%28%29)**()

Returns the address of the endpoint this socket is bound to, ornull if it is not bound yet.

boolean

**[getOOBInline](../../java/net/Socket.html#getOOBInline%28%29)**()

Tests if OOBINLINE is enabled.

[OutputStream](../../java/io/OutputStream.html "class in java.io")

**[getOutputStream](../../java/net/Socket.html#getOutputStream%28%29)**()

Returns an output stream for this socket.

int

**[getPort](../../java/net/Socket.html#getPort%28%29)**()

Returns the remote port number to which this socket is connected.

int

**[getReceiveBufferSize](../../java/net/Socket.html#getReceiveBufferSize%28%29)**()

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

.

[SocketAddress](../../java/net/SocketAddress.html "class in java.net")

**[getRemoteSocketAddress](../../java/net/Socket.html#getRemoteSocketAddress%28%29)**()

Returns the address of the endpoint this socket is connected to, ornull if it is unconnected.

boolean

**[getReuseAddress](../../java/net/Socket.html#getReuseAddress%28%29)**()

Tests if SO_REUSEADDR is enabled.

int

**[getSendBufferSize](../../java/net/Socket.html#getSendBufferSize%28%29)**()

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

**[getSoLinger](../../java/net/Socket.html#getSoLinger%28%29)**()

Returns setting for SO_LINGER.

int

**[getSoTimeout](../../java/net/Socket.html#getSoTimeout%28%29)**()

Returns setting for SO_TIMEOUT.

boolean

**[getTcpNoDelay](../../java/net/Socket.html#getTcpNoDelay%28%29)**()

Tests if TCP_NODELAY is enabled.

int

**[getTrafficClass](../../java/net/Socket.html#getTrafficClass%28%29)**()

Gets traffic class or type-of-service in the IP header for packets sent from this Socket

boolean

**[isBound](../../java/net/Socket.html#isBound%28%29)**()

Returns the binding state of the socket.

boolean

**[isClosed](../../java/net/Socket.html#isClosed%28%29)**()

Returns the closed state of the socket.

boolean

**[isConnected](../../java/net/Socket.html#isConnected%28%29)**()

Returns the connection state of the socket.

boolean

**[isInputShutdown](../../java/net/Socket.html#isInputShutdown%28%29)**()

Returns whether the read-half of the socket connection is closed.

boolean

**[isOutputShutdown](../../java/net/Socket.html#isOutputShutdown%28%29)**()

Returns whether the write-half of the socket connection is closed.

void

**[sendUrgentData](../../java/net/Socket.html#sendUrgentData%28int%29)**(int data)

Send one byte of urgent data on the socket.

void

**[setKeepAlive](../../java/net/Socket.html#setKeepAlive%28boolean%29)**(boolean on)

Enable/disable SO_KEEPALIVE.

void

**[setOOBInline](../../java/net/Socket.html#setOOBInline%28boolean%29)**(boolean on)

Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.

void

**[setPerformancePreferences](../../java/net/Socket.html#setPerformancePreferences%28int,%20int,%20int%29)**(int connectionTime, int latency, int bandwidth)

Sets performance preferences for this socket.

void

**[setReceiveBufferSize](../../java/net/Socket.html#setReceiveBufferSize%28int%29)**(int size)

Sets the SO_RCVBUF option to the specified value for this

Socket

.

void

**[setReuseAddress](../../java/net/Socket.html#setReuseAddress%28boolean%29)**(boolean on)

Enable/disable the SO_REUSEADDR socket option.

void

**[setSendBufferSize](../../java/net/Socket.html#setSendBufferSize%28int%29)**(int size)

Sets the SO_SNDBUF option to the specified value for this

Socket

.

static void

**[setSocketImplFactory](../../java/net/Socket.html#setSocketImplFactory%28java.net.SocketImplFactory%29)**([SocketImplFactory](../../java/net/SocketImplFactory.html "interface in java.net") fac)

Sets the client socket implementation factory for the application.

void

**[setSoLinger](../../java/net/Socket.html#setSoLinger%28boolean,%20int%29)**(boolean on, int linger)

Enable/disable SO_LINGER with the specified linger time in seconds.

void

**[setSoTimeout](../../java/net/Socket.html#setSoTimeout%28int%29)**(int timeout)

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

void

**[setTcpNoDelay](../../java/net/Socket.html#setTcpNoDelay%28boolean%29)**(boolean on)

Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).

void

**[setTrafficClass](../../java/net/Socket.html#setTrafficClass%28int%29)**(int tc)

Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.

void

**[shutdownInput](../../java/net/Socket.html#shutdownInput%28%29)**()

Places the input stream for this socket at "end of stream".

void

**[shutdownOutput](../../java/net/Socket.html#shutdownOutput%28%29)**()

Disables the output stream for this socket.

[String](../../java/lang/String.html "class in java.lang")

**[toString](../../java/net/Socket.html#toString%28%29)**()

Converts this socket to a String.