Java Socket(InetAddress address, int port) Constructor

Syntax

Socket(InetAddress address, int port) constructor from Socket has the following syntax.

public Socket(InetAddress address,  int port)  throws IOException

Example

In the following code shows how to use Socket.Socket(InetAddress address, int port) constructor.


/*from w  w w .j av a  2 s. com*/
import java.net.InetAddress;
import java.net.Socket;

public class Main {
  public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("java.sun.com");
    int port = 80;

    Socket socket = new Socket(addr, port);
  }
}




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder