Programatically connect to another server
instance running Vantage.

@param {Server} server
@param {Integer} port
@param {Object} options
@param {Function} cb
@return {Promise}
@api public
777133
function(server, port, options, cb) {
    return this.client.connect.call(this.client, server, port, options, cb);
  }
1133652
function Connection(opts) {

    EventEmitter.call(this);

    opts = opts || {};

    _.defaults(opts, {
        host: 'localhost',
        port: '11211',
        reconnect: true,
        maxValueSize: 1048576
    });

    this.host = opts.host;
    this.port = opts.port;

    this.commandBuffer = new Immutable.List();

    if (opts.onConnect) {
        this.onConnect = opts.onConnect;
    }

    if (opts.onError) {
        this.onError = opts.onError;
    } else {
        this.onError = function onError(err) { this.emit('error'); console.error(err); };
    }
    this.bufferBeforeError = opts.bufferBeforeError;
    this.netTimeout = opts.netTimeout || 500;
    this.backoffLimit = opts.backoffLimit || 10000;
    this.reconnect = opts.reconnect;
    this.disconnecting = false;
    this.ready = false;
    this.backoff = opts.backoff || 10;
    this.maxValueSize = opts.maxValueSize;
    this.writeBuffer = new Immutable.List();

    this.connect();
}
319227
def s_connect(self, server, port, r_server=None):
        
        with self.lock:
            if not r_server:
                self.send('CONNECT %s %s' % (server, port), error_check=True)
            else:
                self.send('CONNECT %s %s %s' % (server, port, \
                                    r_server), error_check=True)
950262
function Server (transport) {
	MCS.call(this, transport, DomainMCSPDU.SEND_DATA_REQUEST, DomainMCSPDU.SEND_DATA_INDICATION);
	
	// must be readed from protocol
	this.clientCoreData = null;
	this.clientNetworkData = null;
	this.clientSecurityData = null;
	
	// init gcc information
	this.serverCoreData = gcc.serverCoreData();
	this.serverSecurityData = gcc.serverSecurityData();
	this.serverNetworkData = gcc.serverNetworkData(new type.Component([]));
	
	var self = this;
	this.transport.on('connect', function (selectedProtocol) {
		self.serverCoreData.obj.clientRequestedProtocol.value = selectedProtocol;
	}).once('data', function (s) {
		self.recvConnectInitial(s);
	});
}
982234
function(link, cb){
            var options = {
                host: urlArr.hostname,
                port: urlArr.port,
                path: urlArr.path+"?link="+encodeURIComponent(link),
                method: 'GET'
            };
            
            var getRequest = protocol.request(options, function(res){
                var result = "";
                
                if(res.statusCode === 200){
                    res.on('error', function(error) {
                        if(typeof cb === "function")
                            cb(error);
                    });

                    res.on('data', function (chunk) {
                        result += chunk;
                    });

                    res.on('end', function (chunk) {
                        if(typeof cb === "function"){
                            var resultObj = JSON.parse(result);
                            var err = (resultObj.status === "error") ? resultObj["msg"] : null
                            cb(err, resultObj);
                        }                        
                    });
                }
                else{
                    if(typeof cb === "function")
                        cb("Request return HTTP "+res.statusCode);
                }
            });
            
            getRequest.end();
        }
280192
function ChickadeeServer(options) {
  options = options || {};
  var specifiedHttpPort = options.httpPort || HTTP_PORT;
  var httpPort = process.env.PORT || specifiedHttpPort;

  var app = express();
  app.use(bodyParser.json());

  var instance = new Chickadee(options);
  options.app = app;
  instance.configureRoutes(options);

  app.listen(httpPort, function() {
    console.log('chickadee is listening on port', httpPort);
  });

  return instance;
}
1126666
function pingServer(options, cb) {
    count = 0;
    results = [];

    options.address  = options.address || 'localhost';
    options.port     = options.port || 80;
    options.attempts = options.attempts || 1;
    options.timeout  = options.timeout || 1000;

    connectServer(options, cb);
}
714488
function checkPort(port, cb) {
  var server = new net.Server();
  server.on('error', function (err) {
    server.removeAllListeners();
    cb(err);
  });
  server.listen(port, function () {
    server.on('close', function () {
      server.removeAllListeners();
      cb(null, port);
    });
    server.close();
  });
}
779396
function chRoute(client, serverType, msg, cb) {
    const servers = client._station.serversMap[serverType];
    if (!servers || !servers.length) {
        utils.invokeCallback(cb, new Error(`rpc servers not exist with serverType: ${serverType}`));
        return;
    }
    let con;
    if (!client.chParam) {
        client.chParam = {};
    }
    if (client.chParam[serverType]) {
        con = client.chParam[serverType].consistentHash;
    } else {
        client.opts.station = client._station;
        con = new ConsistentHash(servers, client.opts);
    }
    const hashFieldIndex = client.opts.hashFieldIndex;
    const field = msg.args[hashFieldIndex] || JSON.stringify(msg);
    utils.invokeCallback(cb, null, con.getNode(field));
    client.chParam[serverType] = { consistentHash: con };
}
516250
function(middleware, options) {
    if (this.server && this.server.auth) {
      this.server.auth(middleware, options);
    } else {
      throw new Error("vantage.auth is only available in Vantage.IO. Please use this (npm install vantage-io --save)");
    }
    return this;
  }
226064
function Server(opts){
  // Shorthand, no "new" required.
  if (!(this instanceof Server))
    return new Server(...arguments);

  if (typeof opts !== 'object')
    opts = {};

  this.clients = opts.dummies || [];

  this.server = opts.server || new SocketServer(socket => {
    let client = new Client(socket);
    this.clients.push(client);
    this.emit('connection', client);

    client._socket.once('data', handshake.bind(client));
    client.on('handshake-done', () => {
      client._socket.on('data', message.bind(client));
    });
  });
}
1324187
@Override
    public void connect(String server, int port, Map<String, Object> connectionParams, IPendingServiceCallback connectCallback, Object[] connectCallArguments) {
        log.debug("connect server: {} port {} connect - params: {} callback: {} args: {}", new Object[] { server, port, connectionParams, connectCallback, Arrays.toString(connectCallArguments) });
        log.info("{}://{}:{}/{}", new Object[] { protocol, server, port, connectionParams.get("app") });
        this.connectionParams = connectionParams;
        this.connectArguments = connectCallArguments;
        if (!connectionParams.containsKey("objectEncoding")) {
            connectionParams.put("objectEncoding", 0);
        }
        this.connectCallback = connectCallback;
        startConnector(server, port);
    }
283515
function(port) {
      var port = port || this.conf.port || 80;
      var server = this.app.listen(port, function() {
        console.log("WeChat server for %s starts...", self.url);
      });
      server.on('error', function(err) {
        console.log(err);
      });
    }
643138
function startServer(argv, httpPort, httpsPort, certs) {
  console.log('Launching proxy server...');
  console.log('   http: ' + httpPort);
  console.log('  https: ' + httpsPort);

  // Injects a node stream by buffering all data, transforming it, and writing
  // it back out.
  // Module IDs are assigned on demand and rotate 0-126.
  var nextModuleId = 0;
  function injectStream(url, source, target) {
    var moduleId = nextModuleId++;
    if (nextModuleId >= 127) {
      nextModuleId = 0;
    }
    var sourceCode = '';
    source.on('data', function(chunk) {
      sourceCode += chunk;
    });
    source.on('end', function() {
      try {
        var targetCode = transformCode(moduleId, url, sourceCode, argv);
        target.end(targetCode);
      } catch (e) {
        console.log('Error during transformation, writing through.');
        console.log(e);
        target.end(sourceCode);
      }
    });
  };

  // Handles both HTTP and HTTPS requests.
  function handler(req, res) {
    // Support both the ?url= mode and the X-WTF-URL header.
    var targetUrl;
    if (req.headers['x-wtf-url']) {
      targetUrl = req.headers['x-wtf-url'];
    } else {
      var parsedUrl = url.parse(req.url, true);
      var query = parsedUrl.query;
      targetUrl = query.url;
    }
    if (!targetUrl || targetUrl.indexOf('http') != 0) {
      res.writeHead(404, ['Content-Type', 'text/plain']);
      res.end();
      return;
    }

    res.on('error', function(e) {
      console.log('ERROR (source): ' + e);
    });

    var targetModule = targetUrl.indexOf('https') == 0 ? https : http;
    targetModule.get(targetUrl, function(originalRes) {
      // Eat errors, otherwise the app will die.
      originalRes.on('error', function(e) {
        console.log('ERROR (target): ' + e);
      });

      // Pull out content type to see if we are interested in it.
      var supportedContentType = false;
      var contentType = originalRes.headers['content-type'];
      if (contentType && contentType.indexOf(';') != 0) {
        contentType = contentType.substr(0, contentType.indexOf(';'));
      }
      switch (contentType) {
        case 'text/javascript':
        case 'application/javascript':
          supportedContentType = true;
          break;
      }

      // Also parse the URL - some servers don't return content type for some
      // reason.
      var supportedPath = false;
      var contentUrl = url.parse(targetUrl);
      if (path.extname(contentUrl.pathname) == '.js') {
        supportedPath = true;
      }

      if (supportedContentType || supportedPath) {
        var headers = [];
        for (var key in originalRes.headers) {
          if (key == 'content-length') {
            continue;
          }
          headers.push([key, originalRes.headers[key]]);
        }
        res.writeHead(originalRes.statusCode, headers);
        injectStream(targetUrl, originalRes, res);
      } else {
        console.log('Pass-through: ' + targetUrl, contentType);
        res.writeHead(originalRes.statusCode, originalRes.headers);
        originalRes.pipe(res);
      }
    }).on('error', function(e) {
      console.log(e);
      res.writeHead(404, ['Content-Type', 'text/plain']);
      res.end(e.message);
    });
  };

  // HTTP server.
  var httpServer = http.createServer(handler);
  httpServer.listen(httpPort);

  // HTTPS server.
  var httpsServer = https.createServer({
    key: certs.privateKey,
    cert: certs.certificate
  }, handler);
  httpsServer.listen(httpsPort);

  console.log('Server ready, use ctrl-c to exit...');
  console.log('');
}
947478
function on(str, opts, cbk) {
      cbk = (_.isFunction(opts)) ? opts : cbk;
      cbk = cbk || function() {};
      opts = opts || {};
      ssn.server.on(str, function() {
        if (!ssn.server || (!ssn.authenticating && !ssn.authenticated)) {
          //console.log("Not Authenticated. Closing Session.", ssn.authenticating, ssn.authenticated);
          self.parent._send("vantage-close-downstream", "downstream", { sessionId: ssn.id });
          return;
        }
        cbk.apply(self, arguments);
      });
    }
1353346
function (options, cb) {
		let outIP = options.out;
		let stack = options.infra.stack;
		
		if (outIP && stack.options.ElbName) {
			options.soajs.log.debug("Creating SOAJS network.");
			
			dockerUtils.getDeployer(options, (error, deployer) => {
				if(error){
					return cb(error);
				}
				
				deployer.listNetworks({}, (err, networks) => {
					if (err) {
						return cb(err);
					}
					
					let found = false;
					networks.forEach((oneNetwork) => {
						if (oneNetwork.Name === 'soajsnet') {
							found = true;
						}
					});
					
					if(found){
						return cb(null, true);
					}
					else{
						let networkParams = {
							Name: 'soajsnet',
							Driver: 'overlay',
							Internal: false,
							Attachable: true,
							CheckDuplicate: true,
							EnableIPv6: false,
							IPAM: {
								Driver: 'default'
							}
						};
						
						deployer.createNetwork(networkParams, (err) => {
							return cb(err, true);
						});
					}
				});
			});
		}
		else {
			return cb(null, false);
		}
	}
714659
function CoapServer(options) {
  // Superclass Constructor
  EventEmitter.call(this);

  options = options || {};
  this.clientsPath = [];
  this.host = options.host || 'localhost';
  this.port = options.port || 8000;
  this.endpoints = options.endpoints || [];  
  this.websocketEndpoints = {};

  this.route = {};
  this.handlers = {};
  this.server = null;
}