Java Socket(InetAddress address, int port, InetAddress localAddr, int localPort) Constructor

Syntax

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

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

Example

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


/*from ww  w. jav a2  s  .c  o  m*/

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,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