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.
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.
If UDP socket is used, TCP/IP related socket options will not apply.
host | the IP address. | |
port | the port number. | |
stream | if true, create a stream socket;
otherwise, create a datagram socket. |
IOException | if an I/O error occurs when creating the socket. | |
SecurityException | if a security manager exists and its
checkConnect method doesn't allow the operation. | |
IllegalArgumentException | if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. | |
NullPointerException | if host is null. |
java.net.Socket.setSocketImplFactory(java.net.SocketImplFactory), java.net.SocketImpl, java.net.SocketImplFactory.createSocketImpl(), SecurityManager.checkConnect
Diagram: Socket