Creates new `Connection` object
@param uri URI of SyncSocket server (e.g. http://localhost:5579)
@constructor
@public
2863
function Connection(uri) {
    this.channels = {};
    let version = require('../package.json').version;
    let opts = {
        query: 'instanceId=' + 'js_cli_' + version,
        'sync disconnect on unload': true,
        path: '/syncsocket'
    };
    this.socket = io.connect(uri, opts);
    this.bindEvents();
}
220270
public static InetSocketAddress toInetSocketAddress(URI uri) {
		final InetAddress adr = toInetAddress(uri);
		final int port = uri.getPort();
		if (port <= 0) {
			throw new IllegalArgumentException(uri.toString());
		}
		return new InetSocketAddress(adr, port);
	}
945986
function createInternalConnection (mode) {

  var result;

  switch (mode) {
    case 'async':
      result = require('then-request');
      break;
    case 'sync':
      result = require('sync-req');
      break;
    default:
      throw new Error('Expected options.mode to be "async" or "sync" but got ' + JSON.stringify(mode));
  }

  return result;
}
426361
@Override
    public URLStreamHandler createURLStreamHandler(final String protocol) {
        if (null == protocol) {
            throw new IllegalArgumentException("null protocol not allowed");
        }
        if (logger.isTraceEnabled()) {
            logger.trace("need to create URLStreamHandler for protocol {}", protocol);
        }

        final String proto = protocol.toLowerCase();
        if (PROTO_HTTP.equals(proto) || PROTO_HTTPS.equals(proto)) {
            return new URLStreamHandler() {
                @Override
                protected URLConnection openConnection(final URL url) throws IOException {
                    if (logger.isTraceEnabled()) {
                        logger.trace("should open connection to {}", url.toExternalForm());
                    }

                    // URLConnection only has a protected ctor, so we need to go through the URL ctor with the matching handler
                    final URLConnection defaultUrlConnection =
                            new URL(protocol, url.getHost(), url.getPort(), url.getFile(), handlers.get(protocol))
                                    .openConnection();

                    if (!cache.urlShouldBeCached(url)) {
                        if (logger.isTraceEnabled()) {
                            logger.trace("not using cache for {}", url);
                        }
                        return defaultUrlConnection;
                    }

                    final Path cacheFile = cache.filenameForURL(url);
                    // now wrap the defaultUrlConnection
                    if (cache.isCached(url)) {
                        // if cached, always use http connection to prevent ssl handshake. As we are reading from the
                        // cache, this is enough
                        return new CachingHttpURLConnection(cache, (HttpURLConnection) defaultUrlConnection);
                    } else {
                        switch (proto) {
                            case PROTO_HTTP:
                                return new CachingHttpURLConnection(cache, (HttpURLConnection) defaultUrlConnection);
                            case PROTO_HTTPS:
                                return new CachingHttpsURLConnection(cache, (HttpsURLConnection) defaultUrlConnection);
                        }
                    }
                    throw new IOException("no matching handler");
                }

                @Override
                protected URLConnection openConnection(final URL u, final Proxy p) throws IOException {
                    if (logger.isTraceEnabled()) {
                        logger.trace("should open connection to {} via {}", u.toExternalForm(), p);
                    }
                    // URLConnection only has a protected ctor, so we need to go through the URL ctor with the
                    // matching handler to get a default implementation of the needed URLStreamHandler
                    final URLConnection defaultUrlConnection =
                            new URL(protocol, u.getHost(), u.getPort(), u.getFile(), handlers.get(protocol))
                                    .openConnection(p);

                    return defaultUrlConnection;
                }
            };
        }
        // return null to use default ones
        return null;
    }
709753
public NatsConnector addHost(URI uri) {
		if (!Constants.PROTOCOL.equalsIgnoreCase(uri.getScheme())) {
			throw new IllegalArgumentException("Invalid protocol in URL: " + uri);
		}
		hosts.add(uri);
		return this;
	}
890503
protected HttpURLConnection openConnection(URL requestTokenURL) {
    try {
      HttpURLConnection connection = (HttpURLConnection) requestTokenURL.openConnection(selectProxy(requestTokenURL));
      connection.setConnectTimeout(getConnectionTimeout());
      connection.setReadTimeout(getReadTimeout());
      return connection;
    }
    catch (IOException e) {
      throw new OAuthRequestFailedException("Failed to open an OAuth connection.", e);
    }
  }
98558
def createConnection(self):
        """"""
        uri = self.reader.createConnection()
        return Pyro.core.getAttrProxyForURI(uri)
1128156
private Socket connect( URI transportURI ) throws PacketTransportException
    {
        String protocol = transportURI.getScheme();
        String host = transportURI.getHost();
        int port = transportURI.getPort();
        int connectTimeout = settings.getIntProperty(FFMQClientSettings.TRANSPORT_TCP_CONNECT_TIMEOUT, 30);
        
        try
        {
            Socket socket = SocketUtils.setupSocket(createSocket(protocol),
	                                                socketSendBufferSize,
	                                                socketRecvBufferSize); 
            
            log.debug("#"+id+" opening a TCP connection to "+host+":"+port);
            socket.connect(new InetSocketAddress(host,port),connectTimeout*1000);
            
            return socket;
        }
        catch (ConnectException e)
        {
        	log.error("#"+id+" could not connect to "+host+":"+port+" (timeout="+connectTimeout+"s) : "+e.getMessage());
            throw new PacketTransportException("Could not connect to "+host+":"+port+" : "+e.toString());
        }
        catch (Exception e)
        {
            log.error("#"+id+" could not connect to "+host+":"+port+" (timeout="+connectTimeout+"s)",e);
            throw new PacketTransportException("Could not connect to "+host+":"+port+" : "+e.toString());
        }
    }
238225
private HttpURLConnection getConnection(String uri, String postJson, String token) throws IOException {
		int tries = 0;
		IOException last = null;

		while (tries++ <= retries) {
			try {
				return getConnectionOnce(uri, postJson, token);
			} catch (IOException ex) {
				last = ex;
			}
		}

		throw last;
	}
1240940
function buildHttpURL(uri) {
    var port     = weinre_port
    var pathname = weinre_pathname

    if (pathname == "/index.html") pathname = "/"

    if (weinre_protocol == "file:") {
        return uri
    }

    else if (weinre_protocol == "http:") {
        if (port != "") port = ":" + port

        return weinre_protocol + "//" + weinre_host + port + pathname + uri
    }

    else if (weinre_protocol == "https:") {
        if (port != "") port = ":" + port

        return weinre_protocol + "//" + weinre_host + port + pathname + uri
    }
}
1089829
private HttpURLConnection openConnection(URL url) throws IOException {
              HttpURLConnection connection = createConnection(url);
              connection.setUseCaches(true);
              connection.setDoInput(true);
              return connection;
       }
575448
private Socket createConnectedSocket(final String miniRoxUrl) {
		try {
			final Socket initSocket = IO.socket(miniRoxUrl);

			final MiniRoxCallback callback = new MiniRoxCallback();
			
			initSocket.on(Socket.EVENT_CONNECT, callback);
			initSocket.on(Socket.EVENT_CONNECT_ERROR, callback);
			initSocket.on(Socket.EVENT_CONNECT_TIMEOUT, callback);
			initSocket.on(Socket.EVENT_CONNECT_ERROR, callback);
			initSocket.on(Socket.EVENT_DISCONNECT, callback);
			initSocket.on(Socket.EVENT_ERROR, callback);
			
			// Be sure that the emit/ack is synchronous to get the filters before the test are run
			LOGGER.trace("Connection to minirox"); // Unable to use the logger into the run method
			new Thread(new Runnable() {
				@Override
				public void run() {
					initSocket.connect();
				}
			}).start();
			
			synchronized (callback) {
				callback.wait();
			}

			if (!initSocket.connected()) {
				LOGGER.warn("Minirox is not available");
				return null;
			}
			
			return initSocket;
		}
		catch (URISyntaxException | InterruptedException e) {
			LOGGER.warn("Unknown error", e);
		}
		
		return null;
	}
263420
def _create_connection(self):
        
        logging.debug("Initializing new websocket connection.")
        headers = {
            'Authorization': self.service._get_bearer_token(),
            'Predix-Zone-Id': self.ingest_zone_id,
            'Content-Type': 'application/json',
        }
        url = self.ingest_uri

        logging.debug("URL=" + str(url))
        logging.debug("HEADERS=" + str(headers))

        # Should consider connection pooling and longer timeouts
        return websocket.create_connection(url, header=headers)
472187
function ConnectionState(code, stringId, connected) {
  if (arguments.length === 2) {
    connected = stringId;
    stringId = 'NONAME';
  }
  if (!(this instanceof ConnectionState)) {
    return new ConnectionState(code, stringId, connected);
  }

  this.id = stringId;
  this.code = code;
  this.connected = connected;
}
1005964
public URLConnection createURLConnection(URL url) throws IOException {
        URLConnection conn = url.openConnection();
		return conn;
	}
340112
function lookup(uri, opts) {
    if (typeof uri === "object") {
      opts = uri;
      uri = undefined;
    }

    opts = opts || {};

    var parsed = url_1(uri);
    var source = parsed.source;
    var id = parsed.id;
    var path = parsed.path;
    var sameNamespace = cache[id] && path in cache[id].nsps;
    var newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;

    var io;

    if (newConnection) {
      debug("ignoring socket cache for %s", source);
      io = manager(source, opts);
    } else {
      if (!cache[id]) {
        debug("new io instance for %s", source);
        cache[id] = manager(source, opts);
      }
      io = cache[id];
    }
    if (parsed.query && !opts.query) {
      opts.query = parsed.query;
    }
    return io.socket(parsed.path, opts);
  }
635330
protected URI createRedirectUri(String servletpath, UserGroupInformation ugi,
      DatanodeID host, HttpServletRequest request, NameNode nn) throws URISyntaxException {
    final String hostname = host instanceof DatanodeInfo?
        ((DatanodeInfo)host).getHostName(): host.getHost();
    final String scheme = request.getScheme();
    final int port = "https".equals(scheme)?
        (Integer)getServletContext().getAttribute("datanode.https.port")
        : host.getInfoPort();
    // Add namenode address to the URL params
    final String nnAddr = NetUtils.toIpPort(nn.getNameNodeAddress());
    final String filename = request.getPathInfo();
    return new URI(scheme, null, hostname, port, servletpath,
        "filename=" + filename + "&ugi=" + ugi +
        JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnAddr), null);
  }