|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--java.net.Socket
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.
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 | |
protected |
Socket()
Creates an unconnected socket, with the system-default type of SocketImpl. |
|
Socket(InetAddress address,
int port)
Creates a stream socket and connects it to the specified port number at the specified IP address. |
|
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. |
protected |
Socket(SocketImpl impl)
Creates an unconnected Socket with a user-specified SocketImpl. |
|
Socket(java.lang.String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
|
Socket(java.lang.String host,
int port,
boolean stream)
Deprecated. Use DatagramSocket instead for UDP transport. |
|
Socket(java.lang.String host,
int port,
InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote host on the specified remote port. |
| Method Summary | |
void |
close()
Closes this socket. |
int |
getFlowLabel()
Get value of the flow label for this socket, |
InetAddress |
getInetAddress()
Returns the address to which the socket is connected. |
java.io.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. |
int |
getNetAuthenticate()
Get value of the IPV6_AUTH_NETWORK_LEVEL option for this socket, that is the AH policy in tunnel mode that is applied on the socket. |
int |
getNetEncryption()
Get value of the IPV6_ESP_NETWORK_LEVEL option for this socket, that is the ESP policy in tunnel mode that is applied on the socket. |
java.io.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. |
int |
getSoTimeout()
Returns setting for SO_TIMEOUT. |
boolean |
getTcpNoDelay()
Tests if TCP_NODELAY is enabled. |
int |
getTrafficClass()
Get value of the traffic class for this socket, |
int |
getTransportAuthenticate()
Get value of the IPV6_AUTH_TRANS_LEVEL option for this socket, that is the AH policy in transport that is applied on the socket. |
int |
getTransportEncryption()
Get value of the IPV6_ESP_TRANS_LEVEL option for this socket, that is the ESP policy in transport mode that is applied on the socket. |
void |
setFlowLabel(int value)
Set value of the flow label for this socket, |
void |
setNetAuthenticate(int value)
Set value of the IPV6_AH_NETWORK_LEVEL option for this socket, that is the ESP policy in tunnel mode to apply on the socket. |
void |
setNetEncryption(int value)
Set value of the IPV6_ESP_NETWORK_LEVEL option for this socket, that is the ESP policy in tunnel mode to apply on the socket. |
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(java.net.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 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 |
setTrafficClass(int value)
Set value of the traffic class for this socket, |
void |
setTransportAuthenticate(int value)
Set value of the IPV6_AH_TRANS_LEVEL option for this socket, that is the ESP policy in transport mode to apply on the socket. |
void |
setTransportEncryption(int value)
Set value of the IPV6_ESP_TRANS_LEVEL option for this socket, that is the ESP policy in transport mode to apply on the socket. |
java.lang.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 java.net.SocketException
The impl parameter is an instance of a SocketImpl the subclass wishes to use on the Socket.
public Socket(java.lang.String host,
int port)
throws java.net.UnknownHostException,
java.io.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.
If there is a security manager, its
checkConnect method is called
with the host address and port
as its arguments. This could result in a SecurityException.
host - the host name.port - the port number.java.io.IOException - if an I/O error occurs when creating the socket.java.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.setSocketImplFactory(java.net.SocketImplFactory),
SocketImpl,
SocketImplFactory.createSocketImpl(),
SecurityManager.checkConnect(java.lang.String, int)
public Socket(InetAddress address,
int port)
throws java.io.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.
If there is a security manager, its
checkConnect method is called
with the host address and port
as its arguments. This could result in a SecurityException.
address - the IP address.port - the port number.java.io.IOException - if an I/O error occurs when creating the socket.java.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.setSocketImplFactory(java.net.SocketImplFactory),
SocketImpl,
SocketImplFactory.createSocketImpl(),
SecurityManager.checkConnect(java.lang.String, int)
public Socket(java.lang.String host,
int port,
InetAddress localAddr,
int localPort)
throws java.io.IOException
If there is a security manager, its
checkConnect method is called
with the host address and port
as its arguments. This could result in a SecurityException.
host - the name of the remote hostport - the remote portlocalAddr - the local address the socket is bound tolocalPort - the local port the socket is bound tojava.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.SecurityManager.checkConnect(java.lang.String, int)
public Socket(InetAddress address,
int port,
InetAddress localAddr,
int localPort)
throws java.io.IOException
If there is a security manager, its
checkConnect method is called
with the host address and port
as its arguments. This could result in a SecurityException.
address - the remote addressport - the remote portlocalAddr - the local address the socket is bound tolocalPort - the local port the socket is bound tojava.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.SecurityManager.checkConnect(java.lang.String, int)
public Socket(java.lang.String host,
int port,
boolean stream)
throws java.io.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.
If there is a security manager, its
checkConnect method is called
with the host address and port
as its arguments. This could result in a SecurityException.
host - the host name.port - the port number.stream - a boolean indicating whether this is
a stream socket or a datagram socket.java.io.IOException - if an I/O error occurs when creating the socket.java.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.setSocketImplFactory(java.net.SocketImplFactory),
SocketImpl,
SocketImplFactory.createSocketImpl(),
SecurityManager.checkConnect(java.lang.String, int)
public Socket(InetAddress host,
int port,
boolean stream)
throws java.io.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.
If there is a security manager, its
checkConnect method is called
with host.getHostAddress() and port
as its arguments. This could result in a SecurityException.
host - the IP address.port - the port number.stream - if true, create a stream socket;
otherwise, create a datagram socket.java.io.IOException - if an I/O error occurs when creating the socket.java.lang.SecurityException - if a security manager exists and its
checkConnect method doesn't allow the operation.setSocketImplFactory(java.net.SocketImplFactory),
SocketImpl,
SocketImplFactory.createSocketImpl(),
SecurityManager.checkConnect(java.lang.String, int)| Method Detail |
public InetAddress getInetAddress()
public InetAddress getLocalAddress()
public int getPort()
public int getLocalPort()
public java.io.InputStream getInputStream()
throws java.io.IOException
java.io.IOException - if an I/O error occurs when creating the
input stream.
public java.io.OutputStream getOutputStream()
throws java.io.IOException
java.io.IOException - if an I/O error occurs when creating the
output stream.
public void setTcpNoDelay(boolean on)
throws java.net.SocketException
public boolean getTcpNoDelay()
throws java.net.SocketException
public void setSoLinger(boolean on,
int linger)
throws java.net.SocketException
on - whether or not to linger on.linger - how to linger for, if on is true.java.lang.IllegalArgumentException - if the linger value is negative.
public int getSoLinger()
throws java.net.SocketException
public void setSoTimeout(int timeout)
throws java.net.SocketException
public int getSoTimeout()
throws java.net.SocketException
public void setSendBufferSize(int size)
throws java.net.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.java.lang.IllegalArgumentException - if the value is 0 or is
negative.
public int getSendBufferSize()
throws java.net.SocketException
setSendBufferSize(int)
public void setReceiveBufferSize(int size)
throws java.net.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.java.lang.IllegalArgumentException - if the value is 0 or is
negative.
public int getReceiveBufferSize()
throws java.net.SocketException
setReceiveBufferSize(int)
public void close()
throws java.io.IOException
java.io.IOException - if an I/O error occurs when closing this socket.public java.lang.String toString()
String.toString in class java.lang.Object
public static void setSocketImplFactory(java.net.SocketImplFactory fac)
throws java.io.IOException
When an application creates a new client socket, the socket
implementation factory's createSocketImpl method is
called to create the actual socket implementation.
If there is a security manager, this method first calls
the security manager's checkSetFactory method
to ensure the operation is allowed.
This could result in a SecurityException.
fac - the desired factory.java.io.IOException - if an I/O error occurs when setting the
socket factory.java.net.SocketException - if the factory is already defined.java.lang.SecurityException - if a security manager exists and its
checkSetFactory method doesn't allow the operation.SocketImplFactory.createSocketImpl(),
SecurityManager.checkSetFactory()
public void setNetEncryption(int value)
throws java.net.SocketException
value - value of the policy to apply on the socketgetNetEncryption()
public void setTransportEncryption(int value)
throws java.net.SocketException
value - value of the policy to apply on the socketgetTransportEncryption()
public void setNetAuthenticate(int value)
throws java.net.SocketException
value - value of the policy to apply on the socket#getNetworkAuthenticate
public void setTransportAuthenticate(int value)
throws java.net.SocketException
value - value of the policy to apply on the socketgetTransportAuthenticate()
public int getNetEncryption()
throws java.net.SocketException
setNetEncryption(int)
public int getTransportEncryption()
throws java.net.SocketException
setTransportEncryption(int)
public int getNetAuthenticate()
throws java.net.SocketException
setNetAuthenticate(int)
public int getTransportAuthenticate()
throws java.net.SocketException
setTransportAuthenticate(int)
public void setFlowLabel(int value)
throws java.net.SocketException
value - value of the flow labelgetFlowLabel()
public void setTrafficClass(int value)
throws java.net.SocketException
value - value of the traffic classgetTrafficClass()
public int getFlowLabel()
throws java.net.SocketException
setFlowLabel(int)
public int getTrafficClass()
throws java.net.SocketException
setTrafficClass(int)
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||