Example usage for java.net Socket Socket

List of usage examples for java.net Socket Socket

Introduction

In this page you can find the example usage for java.net Socket Socket.

Prototype

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

Source Link

Document

Creates a socket and connects it to the specified remote address on the specified remote port.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 80;

    Socket socket = new Socket("google.com", port, InetAddress.getByName("java2s.com"), port);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 80;

    Socket socket = new Socket("google.com", port, InetAddress.getByName("java2s.com"), port);

    socket.bind(new InetSocketAddress("java2s.com", port));
}

From source file:Main.java

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);
}

From source file:com.cyberway.issue.crawler.fetcher.HeritrixProtocolSocketFactory.java

/**
 * @see #createSocket(java.lang.String,int,java.net.InetAddress,int)
 *//*from   w w  w.  j a  va2 s  .c  om*/
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
        throws IOException, UnknownHostException {
    return new Socket(host, port, localAddress, localPort);
}

From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
        throws IOException {
    final String hostName = address.getHostName();
    final String resolvedHost = resolver.resolve(hostName);
    if (resolvedHost != null && !resolvedHost.equals(hostName)) {
        if (InetAddressUtils.isIPv6Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress,
                    localPort);// w  ww .ja  v  a2 s .  c  om
        } else if (InetAddressUtils.isIPv4Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress,
                    localPort);
        }
    }
    return defaultFactory.createSocket(address, port, localAddress, localPort);
}

From source file:UseFactory.java

public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
            throws IOException, UnknownHostException {

        System.out.println("[creating a custom socket (method 2)]");
        return new Socket(host, port, localHost, localPort);
    }/*w ww . ja  v  a 2  s . c  o  m*/

From source file:UseFactory.java

public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
            throws IOException {

        System.out.println("[creating a custom socket (method 4)]");
        return new Socket(address, port, localAddress, localPort);
    }//from w w  w .java 2 s .com