Java Socket(String host, int port, InetAddress localAddr, int localPort) Constructor

Syntax

Socket(String host, int port, InetAddress localAddr, int localPort) constructor from Socket has the following syntax.

public Socket(String host,  int port,  InetAddress localAddr,  int localPort)  throws IOException

Example

In the following code shows how to use Socket.Socket(String host, int port, InetAddress localAddr, int localPort) constructor.


/*from   ww w. j av  a 2  s .c om*/

import java.net.InetAddress;
import java.net.Socket;

public class Main {
  public static void main(String[] argv) throws Exception {
    int port = 80;
   
    Socket socket = new Socket("google.com", port,InetAddress.getByName("java2s.com"),port);
  }
}




















Home »
  Java Tutorial »
    java.net »




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