Java java.net Socket fields, constructors, methods, implement or subclass

Example usage for Java java.net Socket fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for java.net Socket.

The text is from its open source code.

Subclass

java.net.Socket has subclasses.
Click this link to see all its subclasses.

Constructor

Socket(String host, int port)
Creates a stream socket and connects it to the specified port number on the named host.
Socket(InetAddress address, int port)
Creates a stream socket and connects it to the specified port number at the specified IP address.
Socket(String host, int port, boolean stream)
Creates a stream socket and connects it to the specified port number on the named host.
Socket(InetAddress host, int port, boolean stream)
Creates a socket and connects it to the specified port number at the specified IP address.
Socket(SocketAddress address, SocketAddress localAddr, boolean stream)
Socket(String host, int port, InetAddress localAddr, int localPort)
Creates a socket and connects it to the specified remote host on the specified remote port.
Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
Creates a socket and connects it to the specified remote address on the specified remote port.
Socket(Proxy proxy)
Creates an unconnected socket, specifying the type of proxy, if any, that should be used regardless of any other settings.
Socket(SocketImpl impl)
Creates an unconnected Socket with a user-specified SocketImpl.
Socket()
Creates an unconnected Socket.

Method

voidbind(SocketAddress bindpoint)
Binds the socket to a local address.
voidclose()
Closes this socket.
voidconnect(SocketAddress endpoint)
Connects this socket to the server.
voidconnect(SocketAddress endpoint, int timeout)
Connects this socket to the server with a specified timeout value.
SocketChannelgetChannel()
Returns the unique java.nio.channels.SocketChannel SocketChannel object associated with this socket, if any.
ClassgetClass()
Returns the runtime class of this Object .
InetAddressgetInetAddress()
Returns the address to which the socket is connected.
InputStreamgetInputStream()
Returns an input stream for this socket.
booleangetKeepAlive()
Tests if SocketOptions#SO_KEEPALIVE SO_KEEPALIVE is enabled.
InetAddressgetLocalAddress()
Gets the local address to which the socket is bound.
intgetLocalPort()
Returns the local port number to which this socket is bound.
SocketAddressgetLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.
booleangetOOBInline()
Tests if SocketOptions#SO_OOBINLINE SO_OOBINLINE is enabled.
OutputStreamgetOutputStream()
Returns an output stream for this socket.
intgetPort()
Returns the remote port number to which this socket is connected.
intgetReceiveBufferSize()
Gets the value of the SocketOptions#SO_RCVBUF SO_RCVBUF option for this Socket , that is the buffer size used by the platform for input on this Socket .
SocketAddressgetRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
booleangetReuseAddress()
Tests if SocketOptions#SO_REUSEADDR SO_REUSEADDR is enabled.
intgetSendBufferSize()
Get value of the SocketOptions#SO_SNDBUF SO_SNDBUF option for this Socket , that is the buffer size used by the platform for output on this Socket .
intgetSoLinger()
Returns setting for SocketOptions#SO_LINGER SO_LINGER .
intgetSoTimeout()
Returns setting for SocketOptions#SO_TIMEOUT SO_TIMEOUT .
booleangetTcpNoDelay()
Tests if SocketOptions#TCP_NODELAY TCP_NODELAY is enabled.
intgetTrafficClass()
Gets traffic class or type-of-service in the IP header for packets sent from this Socket

As the underlying network implementation may ignore the traffic class or type-of-service set using #setTrafficClass(int) this method may return a different value than was previously set using the #setTrafficClass(int) method on this Socket.

inthashCode()
Returns a hash code value for the object.
booleanisBound()
Returns the binding state of the socket.
booleanisClosed()
Returns the closed state of the socket.
booleanisConnected()
Returns the connection state of the socket.
booleanisInputShutdown()
Returns whether the read-half of the socket connection is closed.
booleanisOutputShutdown()
Returns whether the write-half of the socket connection is closed.
voidsendUrgentData(int data)
Send one byte of urgent data on the socket.
voidsetKeepAlive(boolean on)
Enable/disable SocketOptions#SO_KEEPALIVE SO_KEEPALIVE .
voidsetOOBInline(boolean on)
Enable/disable SocketOptions#SO_OOBINLINE SO_OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.
voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets performance preferences for this socket.
voidsetReceiveBufferSize(int size)
Sets the SocketOptions#SO_RCVBUF SO_RCVBUF option to the specified value for this Socket .
voidsetReuseAddress(boolean on)
Enable/disable the SocketOptions#SO_REUSEADDR SO_REUSEADDR socket option.
voidsetSendBufferSize(int size)
Sets the SocketOptions#SO_SNDBUF SO_SNDBUF option to the specified value for this Socket .
voidsetSocketImplFactory(SocketImplFactory fac)
Sets the client socket implementation factory for the application.
voidsetSoLinger(boolean on, int linger)
Enable/disable SocketOptions#SO_LINGER SO_LINGER with the specified linger time in seconds.
voidsetSoTimeout(int timeout)
Enable/disable SocketOptions#SO_TIMEOUT SO_TIMEOUT with the specified timeout, in milliseconds.
voidsetTcpNoDelay(boolean on)
Enable/disable SocketOptions#TCP_NODELAY TCP_NODELAY (disable/enable Nagle's algorithm).
voidsetTrafficClass(int tc)
Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.
voidshutdownInput()
Places the input stream for this socket at "end of stream".
voidshutdownOutput()
Disables the output stream for this socket.
StringtoString()
Converts this socket to a String .
voidwait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.