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

protected Socket(SocketImpl impl) throws SocketException 

Source Link

Document

Creates an unconnected Socket with a user-specified SocketImpl.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Proxy proxy = Proxy.NO_PROXY;
    Socket socket = new Socket(proxy);
}

From source file:com.gargoylesoftware.htmlunit.httpclient.SocksConnectionSocketFactory.java

static Socket createSocketWithSocksProxy(final HttpHost socksProxy) {
    final InetSocketAddress address = new InetSocketAddress(socksProxy.getHostName(), socksProxy.getPort());
    final Proxy proxy = new Proxy(Proxy.Type.SOCKS, address);
    return new Socket(proxy);
}

From source file:com.serphacker.serposcope.scraper.http.extensions.ScrapClientPlainConnectionFactory.java

@Override
public Socket createSocket(final HttpContext context) throws IOException {
    InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("proxy.socks");

    if (socksaddr != null) {
        return new Socket(new Proxy(Proxy.Type.SOCKS, socksaddr));
    } else {/*w  w w  .ja v  a2s  . c  om*/
        return new Socket();
    }
}

From source file:fm.last.moji.tracker.impl.AbstractTrackerFactory.java

public Tracker newTracker(InetSocketAddress newAddress) throws TrackerException {
    log.debug("new {}()", TrackerImpl.class.getSimpleName());
    Tracker tracker = null;//from   w w w .  j  ava2  s.  co m
    BufferedReader reader = null;
    Writer writer = null;
    Socket socket = null;
    try {
        socket = new Socket(netConfig.getProxy());
        socket.setSoTimeout(netConfig.getTrackerReadTimeout());
        log.debug("Connecting to: {}:", newAddress, socket.getPort());
        socket.connect(newAddress, netConfig.getTrackerConnectTimeout());
        reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        RequestHandler requestHandler = new RequestHandler(writer, reader);
        tracker = new TrackerImpl(socket, requestHandler);
    } catch (IOException e) {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(socket);
        throw new TrackerException(e);
    }
    return tracker;
}

From source file:ch.bfh.abcvote.util.helpers.SocksConnectionSocketFactory.java

/**
 * ConnectionSocketFactory needed for Socks Proxy
 * @param context the http context/*from  ww  w.  j  a  v  a 2 s  .  com*/
 * @return returns a proxy socket
 */
public Socket createSocket(final HttpContext context) {
    InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address");
    Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
    return new Socket(proxy);
}