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.
Creates a stream socket and connects it to the specified port
number on the named host.
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.
Creates a stream socket and connects it to the specified port
number at the specified IP address.
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.
Creates a socket and connects it to the specified remote host on
the specified remote port. The Socket will also bind() to the local
address and port supplied.
Parameters:
host - the name of the remote host
port - the remote port
localAddr - the local address the socket is bound to
Creates a socket and connects it to the specified remote address on
the specified remote port. The Socket will also bind() to the local
address and port supplied.
Parameters:
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 to
Socket
public Socket(String host,
int port,
boolean stream) throws IOException
Note: Socket() is deprecated.Use DatagramSocket instead for UDP transport.
Creates a stream socket and connects it to the specified port
number on the named host.
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.
Parameters:
host - the host name.
port - the port number.
stream - a boolean indicating whether this is
a stream socket or a datagram socket.
Note: Socket() is deprecated.Use DatagramSocket instead for UDP transport.
Creates a socket and connects it to the specified port number at
the specified IP address.
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.
Parameters:
address - the IP address.
port - the port number.
stream - if true, create a stream socket;
otherwise, create a datagram socket.
public synchronized void setSoTimeout(int timeout) throws SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in
milliseconds. With this option set to a non-zero timeout,
a read() call on the InputStream associated with this Socket
will block for only this amount of time. If the timeout expires,
a java.io.InterruptedIOException is raised, though the
Socket is still valid. The option must be enabled
prior to entering the blocking operation to have effect. The
timeout must be > 0.
A timeout of zero is interpreted as an infinite timeout.
Sets the client socket implementation factory for the
application. The factory can be specified only once.
When an application creates a new client socket, the socket
implementation factory's createSocketImpl method is
called to create the actual socket implementation.
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.