|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.net.Socket
The actual work of the socket is performed by an instance of the
SocketImpl
class. An application, by changing
the socket factory that creates the socket implementation,
can configure itself to create sockets appropriate to the local
firewall.
setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
Constructor Summary | |
Socket()
Creates an unconnected socket, with the system-default type of SocketImpl. |
|
Socket(InetAddress host,
int port,
boolean stream)
Deprecated. Use DatagramSocket instead for UDP transport. |
|
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(InetAddress address,
int port)
Creates a stream socket and connects it to the specified port number at the specified IP address. |
|
Socket(SocketImpl impl)
Creates an unconnected Socket with a user-specified SocketImpl. |
|
Socket(String host,
int port,
boolean stream)
Deprecated. Use DatagramSocket instead for UDP transport. |
|
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(String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
Method Summary | |
void | close()
Closes this socket. |
InetAddress | getInetAddress()
Returns the address to which the socket is connected. |
InputStream | getInputStream()
Returns an input stream for this socket. |
InetAddress | getLocalAddress()
Gets the local address to which the socket is bound. |
int | getLocalPort()
Returns the local port to which this socket is bound. |
OutputStream | getOutputStream()
Returns an output stream for this socket. |
int | getPort()
Returns the remote port to which this socket is connected. |
int | getReceiveBufferSize()
Get value of the SO_RCVBUF option for this socket, that is the buffer size used by the platform for input on the this Socket. |
int | getSendBufferSize()
Get value of the SO_SNDBUF option for this socket, that is the buffer size used by the platform for output on the this Socket. |
int | getSoLinger()
Returns setting for SO_LINGER. -1 returns implies that the option is disabled. |
int | getSoTimeout()
Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e. |
boolean | getTcpNoDelay()
Tests if TCP_NODELAY is enabled. |
void | setReceiveBufferSize(int size)
Sets the SO_RCVBUF option to the specified value for this DatagramSocket. |
void | setSendBufferSize(int size)
Sets the SO_SNDBUF option to the specified value for this DatagramSocket. |
static void | setSocketImplFactory(SocketImplFactory fac)
Sets the client socket implementation factory for the application. |
void | setSoLinger(boolean on,
int linger)
Enable/disable SO_LINGER with the specified linger time. |
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). |
String | toString()
Converts this socket to a String . |
Methods inherited from class java.lang.Object | |
clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait |
Constructor Detail |
protected Socket()
protected Socket(SocketImpl impl) throws SocketException
The impl parameter is an instance of a SocketImpl the subclass wishes to use on the Socket.
public Socket(String host, int port) throws UnknownHostException, IOException
If the application has specified a server socket factory, that
factory's createSocketImpl
method is called to create
the actual socket implementation. Otherwise a "plain" socket is created.
host
- the host name.
port
- the port number.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
public Socket(InetAddress address, int port) throws IOException
If the application has specified a socket factory, that factory's
createSocketImpl
method is called to create the
actual socket implementation. Otherwise a "plain" socket is created.
address
- the IP address.
port
- the port number.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
public Socket(String host, int port, InetAddress localAddr, int localPort) throws IOException
host
- the name of the remote host
port
- the remote port
localAddr
- the local address the socket is bound to
localPort
- the local port the socket is bound topublic Socket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException
address
- the remote address
port
- the remote port
localAddr
- the local address the socket is bound to
localPort
- the local port the socket is bound topublic Socket(String host, int port, boolean stream) throws IOException
If the stream argument is true
, this creates a
stream socket. If the stream argument is false
, it
creates a datagram socket.
If the application has specified a server socket factory, that
factory's createSocketImpl
method is called to create
the actual socket implementation. Otherwise a "plain" socket is created.
host
- the host name.
port
- the port number.
stream
- a boolean
indicating whether this is
a stream socket or a datagram socket.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
public Socket(InetAddress host, int port, boolean stream) throws IOException
If the stream argument is true
, this creates a
stream socket. If the stream argument is false
, it
creates a datagram socket.
If the application has specified a server socket factory, that
factory's createSocketImpl
method is called to create
the actual socket implementation. Otherwise a "plain" socket is created.
address
- the IP address.
port
- the port number.
stream
- if true
, create a stream socket;
otherwise, create a datagram socket.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
Method Detail |
public InetAddress getInetAddress()
public InetAddress getLocalAddress()
public int getPort()
public int getLocalPort()
public InputStream getInputStream() throws IOException
public OutputStream getOutputStream() throws IOException
public void setTcpNoDelay(boolean on) throws SocketException
public boolean getTcpNoDelay() throws SocketException
public void setSoLinger(boolean on, int linger) throws SocketException
on
- whether or not to linger on.
linger
- how to linger for, if on is true.public int getSoLinger() throws SocketException
public void setSoTimeout(int timeout) throws SocketException
public int getSoTimeout() throws SocketException
public void setSendBufferSize(int size) throws SocketException
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
size
- the size to which to set the send buffer
size. This value must be greater than 0.
public int getSendBufferSize() throws SocketException
setSendBufferSize(int)
public void setReceiveBufferSize(int size) throws SocketException
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
size
- the size to which to set the receive buffer
size. This value must be greater than 0.
public int getReceiveBufferSize() throws SocketException
setReceiveBufferSize(int)
public void close() throws IOException
public String toString()
String
.public static void setSocketImplFactory(SocketImplFactory fac) throws IOException
When an application creates a new client socket, the socket
implementation factory's createSocketImpl
method is
called to create the actual socket implementation.
fac
- the desired factory.SocketImplFactory.createSocketImpl()
|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |