| java.lang.Object java.net.Socket
Socket | public class Socket (Code) | | This class represents sockets to be used in connection-oriented (streaming)
protocols.
|
Constructor Summary | |
public | Socket() Construct a connection-oriented Socket. | public | Socket(Proxy proxy) Constructs a connection-oriented Socket with specified proxy . | public | Socket(String dstName, int dstPort) Construct a stream socket connected to the nominated destination
host/port. | public | Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) Construct a stream socket connected to the nominated destination
host/port. | public | Socket(String hostName, int port, boolean streaming) Answer a new socket. | public | Socket(InetAddress dstAddress, int dstPort) Construct a stream socket connected to the nominated destination host
address/port. | public | Socket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort) Construct a stream socket connected to the nominated destination host
address/port. | public | Socket(InetAddress addr, int port, boolean streaming) Answer a new socket. | protected | Socket(SocketImpl anImpl) Creates an unconnected socket, wrapping the socketImpl
argument. |
Method Summary | |
void | accepted() Set the appropriate flags for a Socket created by ServerSocket.accept(). | public void | bind(SocketAddress localAddr) Bind the Socket to the nominated local host/port. | void | checkDestination(InetAddress destAddr, int dstPort) Check the connection destination satisfies the security policy and is in
the valid port range. | public synchronized void | close() Close the socket. | public void | connect(SocketAddress remoteAddr) Connect the Socket to the host/port specified by the SocketAddress. | public void | connect(SocketAddress remoteAddr, int timeout) Connect the Socket to the host/port specified by the SocketAddress with a
specified timeout. | public SocketChannel | getChannel() | public InetAddress | getInetAddress() Returns an
InetAddress instance representing the address this
socket has connected to.
if this socket is connected, the address it is connected to. | public InputStream | getInputStream() Answer the socket input stream, to read byte data off the socket. | public boolean | getKeepAlive() Answer the SO_KEEPALIVE option for this socket. | public InetAddress | getLocalAddress() Returns an
InetAddress instance representing the local
address this socket is bound to. | public int | getLocalPort() Answer the local port to which the socket is bound. | public SocketAddress | getLocalSocketAddress() Answer the local SocketAddress for this socket, or null if the socket is
not bound. | public boolean | getOOBInline() Get the state of the SO_OOBINLINE socket option. | public OutputStream | getOutputStream() Answer the socket output stream, for writing byte data on the socket. | public int | getPort() Returns the number of the remote port this socket is connected to.
int the remote port number that this socket has connected to. | public synchronized int | getReceiveBufferSize() Answer the socket receive buffer size (SO_RCVBUF). | public SocketAddress | getRemoteSocketAddress() Answer the remote SocketAddress for this socket, or null if the socket is
not connected. | public boolean | getReuseAddress() Get the state of the SO_REUSEADDR socket option. | public synchronized int | getSendBufferSize() Answer the socket send buffer size (SO_SNDBUF). | public int | getSoLinger() Answer the linger-on-close timeout for this socket (the SO_LINGER value).
this socket's SO_LINGER value. | public synchronized int | getSoTimeout() Answer the socket read timeout. | public boolean | getTcpNoDelay() Answer true if the socket is using Nagle's algorithm. | public int | getTrafficClass() Get the IP_TOS socket option. | public boolean | isBound() Return if the socket is bound to a local address and port. | public boolean | isClosed() Return if the socket is closed. | public boolean | isConnected() Return if the socket is connected. | public boolean | isInputShutdown() Return if
Socket.shutdownInput has been called. | public boolean | isOutputShutdown() Return if
Socket.shutdownOutput has been called. | static boolean | preferIPv4Stack() | public void | sendUrgentData(int value) Send the single byte of urgent data on the socket. | public void | setKeepAlive(boolean value) Set the SO_KEEPALIVE option for this socket. | public void | setOOBInline(boolean oobinline) Set the SO_OOBINLINE socket option. | public void | setPerformancePreferences(int connectionTime, int latency, int bandwidth) | public synchronized void | setReceiveBufferSize(int size) Set the socket receive buffer size. | public void | setReuseAddress(boolean reuse) Set the SO_REUSEADDR socket option. | public synchronized void | setSendBufferSize(int size) Set the socket send buffer size. | public void | setSoLinger(boolean on, int timeout) Set the SO_LINGER option, with the specified time, in seconds. | public synchronized void | setSoTimeout(int timeout) Set the read timeout on this socket. | public static synchronized void | setSocketImplFactory(SocketImplFactory fac) Specifies the application's socket implementation factory. | public void | setTcpNoDelay(boolean on) Set whether the socket is to use Nagle's algorithm. | public void | setTrafficClass(int value) Set the IP_TOS socket option. | public void | shutdownInput() Shutdown the input portion of the socket. | public void | shutdownOutput() Shutdown the output portion of the socket. | void | startupSocket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort, boolean streaming) Creates a stream socket, binds it to the nominated local address/port,
then connects it to the nominated destination address/port. | public String | toString() Answers a string containing a concise, human-readable description of the
socket. |
FLAG_SHUTDOWN | final static int FLAG_SHUTDOWN(Code) | | |
MULTICAST_IF | final static int MULTICAST_IF(Code) | | |
MULTICAST_TTL | final static int MULTICAST_TTL(Code) | | |
TCP_NODELAY | final static int TCP_NODELAY(Code) | | |
Socket | public Socket()(Code) | | Construct a connection-oriented Socket. The Socket is created in the
factory if declared, or otherwise of the default type.
See Also: SocketImplFactory |
Socket | public Socket(Proxy proxy)(Code) | | Constructs a connection-oriented Socket with specified proxy .
Method checkConnect is called if a security manager
exists, and the proxy host address and port number are passed as
parameters.
Parameters: proxy - the specified proxy for this Socket. throws: IllegalArgumentException - if the proxy is null or of an invalid type. throws: SecurityException - if a security manager exists and it denies the permission toconnect to proxy. |
Socket | public Socket(String dstName, int dstPort) throws UnknownHostException, IOException(Code) | | Construct a stream socket connected to the nominated destination
host/port. By default, the socket binds it to any available port on the
default localhost.
Parameters: dstName - the destination host to connect to Parameters: dstPort - the port on the destination host to connect to throws: UnknownHostException - if the host cannot be resolved throws: IOException - if an error occurs while instantiating the socket |
Socket | public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException(Code) | | Construct a stream socket connected to the nominated destination
host/port. The socket is bound it to the nominated localAddress/port.
Parameters: dstName - the destination host to connect to Parameters: dstPort - the port on the destination host to connect to Parameters: localAddress - the local host address to bind to Parameters: localPort - the local port to bind to throws: UnknownHostException - if the host cannot be resolved throws: IOException - if an error occurs while instantiating the socket |
Socket | public Socket(String hostName, int port, boolean streaming) throws IOException(Code) | | Answer a new socket. This constructor is deprecated.
Parameters: hostName - the host name Parameters: port - the port on the host Parameters: streaming - if true, answer a stream socket, else answer a a datagramsocket. throws: UnknownHostException - if the host cannot be resolved throws: IOException - if an error occurs while instantiating the socket See Also: Socket.Socket(String,int) |
Socket | public Socket(InetAddress dstAddress, int dstPort) throws IOException(Code) | | Construct a stream socket connected to the nominated destination host
address/port. By default, the socket binds it to any available port on
the default localhost.
Parameters: dstAddress - the destination host address to connect to Parameters: dstPort - the port on the destination host to connect to throws: IOException - if an error occurs while instantiating the socket |
Socket | public Socket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort) throws IOException(Code) | | Construct a stream socket connected to the nominated destination host
address/port. The socket is bound it to the nominated localAddress/port.
Parameters: dstAddress - the destination host address to connect to Parameters: dstPort - the port on the destination host to connect to Parameters: localAddress - the local host address to bind to Parameters: localPort - the local port to bind to throws: IOException - if an error occurs while instantiating the socket |
Socket | public Socket(InetAddress addr, int port, boolean streaming) throws IOException(Code) | | Answer a new socket. This constructor is deprecated.
Parameters: addr - the internet address Parameters: port - the port on the host Parameters: streaming - if true, answer a stream socket, else answer a datagramsocket. throws: UnknownHostException - if the host cannot be resolved throws: IOException - if an error occurs while instantiating the socket See Also: Socket.Socket(InetAddress,int) |
Socket | protected Socket(SocketImpl anImpl) throws SocketException(Code) | | Creates an unconnected socket, wrapping the socketImpl
argument.
Parameters: anImpl - the socket to wrap throws: SocketException - if an error occurs assigning the implementation |
bind | public void bind(SocketAddress localAddr) throws IOException(Code) | | Bind the Socket to the nominated local host/port.
Parameters: localAddr - the local machine address and port to bind on throws: IllegalArgumentException - if the SocketAddress is not supported throws: IOException - if the socket is already bound, or a problem occurs duringthe bind |
checkDestination | void checkDestination(InetAddress destAddr, int dstPort)(Code) | | Check the connection destination satisfies the security policy and is in
the valid port range.
Parameters: destAddr - the destination host address Parameters: dstPort - the port on the destination host |
close | public synchronized void close() throws IOException(Code) | | Close the socket. It is not valid to use the socket thereafter.
throws: IOException - if an error occurs during the close |
connect | public void connect(SocketAddress remoteAddr) throws IOException(Code) | | Connect the Socket to the host/port specified by the SocketAddress.
Parameters: remoteAddr - the remote machine address and port to connect to throws: IllegalArgumentException - if the SocketAddress is not supported throws: IOException - if the socket is already connected, or a problem occursduring the connect |
connect | public void connect(SocketAddress remoteAddr, int timeout) throws IOException(Code) | | Connect the Socket to the host/port specified by the SocketAddress with a
specified timeout.
Parameters: remoteAddr - the remote machine address and port to connect to Parameters: timeout - the millisecond timeout value, the connect will blockindefinitely for a zero value. throws: IllegalArgumentException - if the timeout is negative, or the SocketAddress is notsupported throws: IOException - if the socket is already connected, or a problem occursduring the connect |
getChannel | public SocketChannel getChannel()(Code) | | if Socket is created by a SocketChannel, returns the related
SocketChannel
the related SocketChannel |
getInetAddress | public InetAddress getInetAddress()(Code) | | Returns an
InetAddress instance representing the address this
socket has connected to.
if this socket is connected, the address it is connected to. Anull return signifies no connection has been made. |
getInputStream | public InputStream getInputStream() throws IOException(Code) | | Answer the socket input stream, to read byte data off the socket. Note,
multiple input streams may be created on a single socket.
a byte oriented read stream for this socket throws: IOException - if an error occurs creating the stream See Also: org.apache.harmony.luni.net.SocketInputStream |
getKeepAlive | public boolean getKeepAlive() throws SocketException(Code) | | Answer the SO_KEEPALIVE option for this socket.
the socket SO_KEEPALIVE option setting throws: SocketException - if an error occurs on the option access |
getLocalAddress | public InetAddress getLocalAddress()(Code) | | Returns an
InetAddress instance representing the local
address this socket is bound to.
the local address that this socket has bound to |
getLocalPort | public int getLocalPort()(Code) | | Answer the local port to which the socket is bound.
the local port to which the socket is bound |
getLocalSocketAddress | public SocketAddress getLocalSocketAddress()(Code) | | Answer the local SocketAddress for this socket, or null if the socket is
not bound.
This is useful on multihomed hosts.
the local socket address |
getOOBInline | public boolean getOOBInline() throws SocketException(Code) | | Get the state of the SO_OOBINLINE socket option.
true if the SO_OOBINLINE is enabled,false otherwise. throws: SocketException - if the socket is closed or the option is invalid. |
getOutputStream | public OutputStream getOutputStream() throws IOException(Code) | | Answer the socket output stream, for writing byte data on the socket.
Note, multiplie output streams may be created on a single socket.
OutputStream a byte oriented write stream for this socket throws: IOException - if an error occurs creating the stream See Also: org.apache.harmony.luni.net.SocketOutputStream |
getPort | public int getPort()(Code) | | Returns the number of the remote port this socket is connected to.
int the remote port number that this socket has connected to. Areturn of 0 (zero) indicates that there is noconnection in place. |
getReceiveBufferSize | public synchronized int getReceiveBufferSize() throws SocketException(Code) | | Answer the socket receive buffer size (SO_RCVBUF).
socket receive buffer size throws: SocketException - if an error occurs on the option access |
getRemoteSocketAddress | public SocketAddress getRemoteSocketAddress()(Code) | | Answer the remote SocketAddress for this socket, or null if the socket is
not connected.
the remote socket address |
getReuseAddress | public boolean getReuseAddress() throws SocketException(Code) | | Get the state of the SO_REUSEADDR socket option.
true if the SO_REUSEADDR is enabled,false otherwise. throws: SocketException - if the socket is closed or the option is invalid. |
getSendBufferSize | public synchronized int getSendBufferSize() throws SocketException(Code) | | Answer the socket send buffer size (SO_SNDBUF).
socket send buffer size throws: SocketException - if an error occurs on the option access |
getSoLinger | public int getSoLinger() throws SocketException(Code) | | Answer the linger-on-close timeout for this socket (the SO_LINGER value).
this socket's SO_LINGER value. A value of -1 willbe returned if the option is not enabled. throws: SocketException - if an error occurs on querying this property |
getSoTimeout | public synchronized int getSoTimeout() throws SocketException(Code) | | Answer the socket read timeout. The SO_TIMEOUT option, a value of 0
indicates it is disabled and a read operation will block indefinitely
waiting for data.
the socket read timeout throws: SocketException - if an error occurs on the option access |
getTcpNoDelay | public boolean getTcpNoDelay() throws SocketException(Code) | | Answer true if the socket is using Nagle's algorithm. The TCP_NODELAY
option setting.
the socket TCP_NODELAY option setting throws: SocketException - if an error occurs on the option access |
getTrafficClass | public int getTrafficClass() throws SocketException(Code) | | Get the IP_TOS socket option.
the IP_TOS socket option value throws: SocketException - if the option is invalid |
isBound | public boolean isBound()(Code) | | Return if the socket is bound to a local address and port.
true if the socket is bound to a local address,false otherwise. |
isClosed | public boolean isClosed()(Code) | | Return if the socket is closed.
true if the socket is closed, false otherwise. |
isConnected | public boolean isConnected()(Code) | | Return if the socket is connected.
true if the socket is connected,false otherwise. |
isInputShutdown | public boolean isInputShutdown()(Code) | | Return if
Socket.shutdownInput has been called.
true if shutdownInput has beencalled, false otherwise. |
isOutputShutdown | public boolean isOutputShutdown()(Code) | | Return if
Socket.shutdownOutput has been called.
true if shutdownOutput has beencalled, false otherwise. |
preferIPv4Stack | static boolean preferIPv4Stack()(Code) | | |
sendUrgentData | public void sendUrgentData(int value) throws IOException(Code) | | Send the single byte of urgent data on the socket.
Parameters: value - the byte of urgent data exception: IOException - when an error occurs sending urgent data |
setKeepAlive | public void setKeepAlive(boolean value) throws SocketException(Code) | | Set the SO_KEEPALIVE option for this socket.
Parameters: value - the socket SO_KEEPALIVE option setting throws: SocketException - if an error occurs setting the option |
setOOBInline | public void setOOBInline(boolean oobinline) throws SocketException(Code) | | Set the SO_OOBINLINE socket option. When this option is enabled, out of
band data is recieved in the normal data stream.
Parameters: oobinline - the socket SO_OOBINLINE option setting throws: SocketException - if the socket is closed or the option is invalid. |
setPerformancePreferences | public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)(Code) | | sets performance preference for connectionTime,latency and bandwidth
Parameters: connectionTime - the importance of connect time Parameters: latency - the importance of latency Parameters: bandwidth - the importance of bandwidth |
setReceiveBufferSize | public synchronized void setReceiveBufferSize(int size) throws SocketException(Code) | | Set the socket receive buffer size.
Parameters: size - the buffer size, in bytes throws: SocketException - tf an error occurs while setting the size or the size isinvalid. |
setReuseAddress | public void setReuseAddress(boolean reuse) throws SocketException(Code) | | Set the SO_REUSEADDR socket option.
Parameters: reuse - the socket SO_REUSEADDR option setting throws: SocketException - if the socket is closed or the option is invalid. |
setSendBufferSize | public synchronized void setSendBufferSize(int size) throws SocketException(Code) | | Set the socket send buffer size.
Parameters: size - the buffer size, in bytes throws: SocketException - if an error occurs while setting the size or the size isinvalid. |
setSoLinger | public void setSoLinger(boolean on, int timeout) throws SocketException(Code) | | Set the SO_LINGER option, with the specified time, in seconds. The
SO_LINGER option is silently limited to 65535 seconds.
Parameters: on - if linger is enabled Parameters: timeout - the linger timeout value, in seconds throws: SocketException - if an error occurs setting the option |
setSoTimeout | public synchronized void setSoTimeout(int timeout) throws SocketException(Code) | | Set the read timeout on this socket. The SO_TIMEOUT option, is specified
in milliseconds. The read operation will block indefinitely for a zero
value.
Parameters: timeout - the read timeout value throws: SocketException - if an error occurs setting the option |
setSocketImplFactory | public static synchronized void setSocketImplFactory(SocketImplFactory fac) throws IOException(Code) | | Specifies the application's socket implementation factory. This may only
be executed the once over the lifetime of the application.
Parameters: fac - the socket factory to set exception: IOException - thrown if the factory has already been set |
setTcpNoDelay | public void setTcpNoDelay(boolean on) throws SocketException(Code) | | Set whether the socket is to use Nagle's algorithm. The TCP_NODELAY
option setting.
Parameters: on - the socket TCP_NODELAY option setting throws: SocketException - if an error occurs setting the option |
setTrafficClass | public void setTrafficClass(int value) throws SocketException(Code) | | Set the IP_TOS socket option.
Parameters: value - the socket IP_TOS setting throws: SocketException - if the socket is closed or the option is invalid. |
shutdownInput | public void shutdownInput() throws IOException(Code) | | Shutdown the input portion of the socket.
throws: IOException - if an error occurs while closing the socket input throws: SocketException - if the socket is closed |
shutdownOutput | public void shutdownOutput() throws IOException(Code) | | Shutdown the output portion of the socket.
throws: IOException - if an error occurs while closing the socket output throws: SocketException - if the socket is closed |
startupSocket | void startupSocket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort, boolean streaming) throws IOException(Code) | | Creates a stream socket, binds it to the nominated local address/port,
then connects it to the nominated destination address/port.
Parameters: dstAddress - the destination host address Parameters: dstPort - the port on the destination host Parameters: localAddress - the address on the local machine to bind Parameters: localPort - the port on the local machine to bind throws: IOException - thrown if a error occurs during the bind or connectoperations |
toString | public String toString()(Code) | | Answers a string containing a concise, human-readable description of the
socket.
the description |
|
|