Base websocket URL that is advertised to external clients.

    Useful when the websocket URL advertised to the clients needs to be
    customized (typically when running behind NAT, firewall, etc.)
342598
def base_ws_uri():
    

    scheme = config['wsserver']['advertised_scheme']
    host = config['wsserver']['advertised_host']
    port = config['wsserver']['advertised_port']
    return '{}://{}:{}'.format(scheme, host, port)
99858
function determineBaseURL(url) {

	var baseURL;

	// Check if url is set
	if (url) {

		// Remove whitespace
		baseURL = url.trim();

		baseURL = correctHttpAndHttps(baseURL);
		baseURL = correctQuestionMarkAndAnd(baseURL);
		baseURL = removeParameters(baseURL);

	} else {
		// Throw error (no url)
		throw new Error('The url parameter is not set.');
	}

	return baseURL;
}
41826
function ws(argv, callback) {
  if (!argv[2]) {
    console.error("url is required");
    console.error("Usage : ws <url>");
    process.exit(-1);
  }
  var uri = argv[2];
  var updatesVia = 'wss://' + uri.split('/')[2] + '/';

  var s;

  var connect = function(){
    s = new wss(updatesVia, {
      origin: 'http://websocket.org'
    });

    s.on('error', function() {
      callback('socket error');
      setTimeout(connect, RECONNECT);
    });

    s.on('open', function open() {
      var sub = 'sub ' + uri;
      callback(null, sub);
      s.send(sub);

      // periodically ping server
      setInterval(function() {
        var message = 'ping';
        debug(null, message);
        s.send(message);
      }, INTERVAL);
    });

  };
  connect();

  s.on('message', function message(data, flags) {
    callback(null, data);
  });

}
145091
private String serverUrl() {
        if (context.containsKey(AgentBootstrapperArgs.SERVER_URL)) {
            return (String) context.get(AgentBootstrapperArgs.SERVER_URL);
        } else {
            return "http://" + context.get("hostname") + ":" + context.get("port") + "/go";
        }
    }
380097
def websocket(
        self, uri, host=None, strict_slashes=None, subprotocols=None, name=None
    ):
        
        self.enable_websocket()

        # Fix case where the user did not prefix the URL with a /
        # and will probably get confused as to why it's not working
        if not uri.startswith("/"):
            uri = "/" + uri

        if strict_slashes is None:
            strict_slashes = self.strict_slashes

        def response(handler):
            async def websocket_handler(request, *args, **kwargs):
                request.app = self
                if not getattr(handler, "__blueprintname__", False):
                    request.endpoint = handler.__name__
                else:
                    request.endpoint = (
                        getattr(handler, "__blueprintname__", "")
                        + handler.__name__
                    )
                try:
                    protocol = request.transport.get_protocol()
                except AttributeError:
                    # On Python3.5 the Transport classes in asyncio do not
                    # have a get_protocol() method as in uvloop
                    protocol = request.transport._protocol
                ws = await protocol.websocket_handshake(request, subprotocols)

                # schedule the application handler
                # its future is kept in self.websocket_tasks in case it
                # needs to be cancelled due to the server being stopped
                fut = ensure_future(handler(request, ws, *args, **kwargs))
                self.websocket_tasks.add(fut)
                try:
                    await fut
                except (CancelledError, ConnectionClosed):
                    pass
                finally:
                    self.websocket_tasks.remove(fut)
                await ws.close()

            self.router.add(
                uri=uri,
                handler=websocket_handler,
                methods=frozenset({"GET"}),
                host=host,
                strict_slashes=strict_slashes,
                name=name,
            )
            return handler

        return response
1260028
function RpcTunnel(url, sslSettings) {
		var self = this;
		if (! (this instanceof RpcTunnel)) {
			return new RpcTunnel(url, sslSettings);
		}

		this.transports = {};

		if (!url) {
			throw new Error('Missing url parameter, which should be either a URL or client transport.')
		}

		var transport = null;

		if (typeof url === 'string') {
			var HttpTransport = require('./transports/http');
			transport = new HttpTransport(url, sslSettings);

			// As a special case when adding an HTTP transport, set up the WebSocket transport
			// It is lazy-loaded, so the WebSocket connection is only created if/when the transport is used
			Object.defineProperty(this.transports, 'ws', {
				enumerable: true, // JSWS-47 ensure we can discover the ws transport
				get: (function () {
					var webSocketTransport;
					var WebSocketTransport = require('./transports/ws');
					return function () {
						if (!webSocketTransport) {
							webSocketTransport = new WebSocketTransport(url, sslSettings);
							webSocketTransport.on('event', function (e) {
								self.emit('event', e);
							});
						}
						return webSocketTransport;
					};
				}())
			});
		} else {
			transport = url;
			transport.on('event', function (e) {
				self.emit('event', e);
			});
		}

		transport.on('error', function(err) {
			self.emit('error', err);
		});

		this.url = transport.url;
		this.transports[transport.name] = transport;
	}
1229753
def default(request):
    
    protocol = request.is_secure() and 'wss://' or 'ws://'
    heartbeat_msg = settings.WS4REDIS_HEARTBEAT and '"{0}"'.format(settings.WS4REDIS_HEARTBEAT) or 'null'
    context = {
        'WEBSOCKET_URI': protocol + request.get_host() + settings.WEBSOCKET_URL,
        'WS4REDIS_HEARTBEAT': mark_safe(heartbeat_msg),
    }
    return context
674975
function fromWebSocketURL(url) {

  if (typeof WebSocket != "undefined") {
    return require("./channels/WebSocket").createChannel(url, protocol)
  }

  // indirect so that browserify won't package it
  var mod_WebSocketConnection = "./channels/WebSocketConnection"

  return require(mod_WebSocketConnection).createChannel(url, protocol)
}
1104943
public static String externalUrl(final IRI identifier, final String baseUrl) {
        if (baseUrl.endsWith("/")) {
            return replaceOnce(identifier.getIRIString(), TRELLIS_DATA_PREFIX, baseUrl);
        }
        return replaceOnce(identifier.getIRIString(), TRELLIS_DATA_PREFIX, baseUrl + "/");
    }
762034
def get_base_url(self):
        
        return "http://{hostname}:{port}/{api}".format(
                hostname=self.hostname,
                port=self.port,
                api=self.api_version)
937915
function MokouWebsocket(url, protocols) {
  this.protocols = protocols || [];
  this.url = url;
  /**
   * Websocket state
   * @type {number}
   */
  this.readyState = WebSocket.CONNECTING;

  this.reconnectInterval = 1000;
  this.timeoutInterval = 2000;

  let ws;
  let forcedClose = false;

  const self = this;

  /**
   * Websocket on open event
   * @param {{}} e - WebSocket event
   */
  this.onopen = function (e) {
    return e;
  };
  /**
   * Websocket on close event
   * @param {{}} e - WebSocket event
   */
  this.onclose = function (e) {
    return e;
  };
  /**
   * Websocket on connectiong event
   * @param {{}} e - WebSocket event
   */
  this.onconnecting = function (e) {
    return e;
  };
  /**
   * Websocket on error event
   * @param {{}} e - WebSocket event
   */
  this.onerror = function (e) {
    return e;
  };
  /**
   * Websocket on message event
   * @param {{}} e - WebSocket event
   */
  this.onmessage = function (e) {
    return e;
  };

  /**
   * Attempt to connect (reconnect) to websocket server
   * @param {boolean} [reconnectAttempt=false] - indicates if MokouWebSocket trying to reconnect to server
   */
  function connect(reconnectAttempt) {
    reconnectAttempt = reconnectAttempt || false;

    ws = new WebSocket(self.url, self.protocols);
    self.emit('connecting');
    self.onconnecting();

    const timeout = setTimeout(() => {
      ws.close();
    }, self.timeoutInterval);

    ws.onopen = function (e) {
      clearTimeout(timeout);
      self.readyState = WebSocket.OPEN;
      reconnectAttempt = false;
      self.emit('open', e);
      self.onopen(e);
    };

    ws.onclose = function (e) {
      clearTimeout(timeout);
      ws = null;
      if (forcedClose) {
        self.readyState = WebSocket.CLOSED;
        self.emit('close', e);
        self.onclose(e);
      }
      else {
        self.readyState = WebSocket.CONNECTING;
        self.emit('connecting');
        self.onconnecting();
        if (!reconnectAttempt) {
          self.emit('close', e);
          self.onclose(e);
        }
        setTimeout(() => {
          connect(true);
        }, self.reconnectInterval);
      }
    };

    ws.on('message', (e) => {
      self.emit('message', e);
      self.onmessage(e);
    });

    ws.onerror = function (e) {
      clearTimeout(timeout);
      ws = null;
      if (forcedClose) {
        self.readyState = WebSocket.CLOSED;
        self.emit('close', e);
        self.onclose(e);
      }
      else {
        self.readyState = WebSocket.CONNECTING;
        self.emit('connecting');
        self.onconnecting();
        if (!reconnectAttempt) {
          self.emit('close', e);
          self.onclose(e);
        }
        setTimeout(() => {
          connect(true);
        }, self.reconnectInterval);
      }
      self.emit('error', e);
      self.onerror(e);
    };
  }

  connect(false);

  /**
   * Sends given string to the other side
   * @param {string} data
   */
  this.send = function (data) {
    if (ws) {
      ws.send(data);
    }
    else {
      throw new Error('Mokou-websocket: WebSocket closed.');
    }
  };

  /**
   * Close WebSocket connection
   */
  this.close = function () {
    if (ws) {
      forcedClose = true;
      ws.close();
      ws = null;
    }
  };

  /**
   * Refresh WebSocket connection
   */
  this.refresh = function () {
    if (ws) {
      ws.close();
    }
  };
}
117696
def base_url(self, value):
        
        logger.debug('StackInABoxService ({0}:{1}) Updating Base URL '
                     'from {2} to {3}'
                     .format(self.__id,
                             self.name,
                             self.__base_url,
                             value))
        self.__base_url = value
        for k, v in six.iteritems(self.routes):
            v['regex'] = StackInABoxService.get_service_regex(
                value,
                v['uri'],
                v['handlers'].is_subservice)
573506
function url(path) {
        if (path) {
            if (_.startsWith(path, "/")) {
                if (!_urlPrefix) {
                    // lets discover the base url via the base html element
                    _urlPrefix = $('base').attr('href') || "";
                    if (_.endsWith(_urlPrefix, '/')) {
                        _urlPrefix = _urlPrefix.substring(0, _urlPrefix.length - 1);
                    }
                }
                if (_urlPrefix) {
                    return _urlPrefix + path;
                }
            }
        }
        return path;
    }
691156
def _build_url(self, endpoint):
        
        try:
            path = self.endpoints[endpoint]
        except KeyError:
            msg = 'Unknown endpoint `{0}`'
            raise ValueError(msg.format(endpoint))
        absolute_url = urljoin(self.target, path)
        return absolute_url
882771
public final HttpClient baseUrl(String baseUrl) {
		Objects.requireNonNull(baseUrl, "baseUrl");
		return tcpConfiguration(tcp -> tcp.bootstrap(b -> HttpClientConfiguration.baseUrl(b, baseUrl)));
	}
935990
function WebSocket(url, opt_protocols) {
    var scope = ctorEvent();
    goog.base(this, descriptor);

    /**
     * Underlying WS.
     * @type {!WebSocket}
     * @private
     */
    this.handle_ = arguments.length == 1 ?
        new originalWs(url) :
        new originalWs(url, opt_protocols);

    /**
     * Event type trackers, by name.
     * @type {!Object.<Function>}
     * @private
     */
    this.trackers_ = {};

    /**
     * Properties, accumulated during setup before send().
     * @type {!Object}
     * @private
     */
    this.props_ = {
      'url': url,
      'protocol': opt_protocols
    };

    wtf.trace.Scope.leave(scope);
  }
617229
function(bs, done) {
        /**
         * An extra port is not needed in snippet/server mode
         */
        if (bs.options.get("mode") !== "proxy") {
            return done();
        }

        /**
         * Web socket support is disabled by default
         */
        if (!bs.options.getIn(["proxy", "ws"])) {
            return done();
        }

        /**
         * Use 1 higher than server port by default...
         */
        var socketPort = bs.options.get("port") + 1;

        /**
         * Or use the user-defined socket.port option instead
         */
        if (bs.options.hasIn(["socket", "port"])) {
            socketPort = bs.options.getIn(["socket", "port"]);
        }

        utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
            if (err) {
                return utils.fail(true, err, bs.cb);
            }
            done(null, {
                optionsIn: [
                    {
                        path: ["socket", "port"],
                        value: port
                    }
                ]
            });
        });
    }