Start a new relay from a pair of given ports
@param  {integer[]} portPair - [devicePort, relayPort]
964182
function startRelay(portPair) {
  var devicePort = portPair[0]
    , relayPort = portPair[1];

  console.log('Starting relay from local port: %s -> device port: %s',
    relayPort, devicePort);

  new usbmux.Relay(devicePort, relayPort, {udid: argv.udid})
    .on('error', onErr)
    .on('warning', console.log.bind(console, 'Warning: device not found...'))
    .on('ready',      info.bind(this, 'Device ready: '))
    .on('attached',   info.bind(this, 'Device attached: '))
    .on('detached',   info.bind(this, 'Device detached: '))
    .on('connect',    info.bind(this, 'New connection to relay started.'))
    .on('disconnect', info.bind(this, 'Connection to relay closed.'))
    .on('close',      info.bind(this, 'Relay has closed.'));
}
730902
function parsePorts(arg) {
  // coerce and split
  var ports = ('' + arg).split(':');
  if (ports.length !== 2) {
    panic('Error parsing ports.');
  }

  // parse ints
  var devicePort = Number((ports[0] === '') ? NaN : ports[0])
    , relayPort = Number((ports[1] === '') ? NaN : ports[1]);

  // NaN check em
  if (devicePort !== devicePort || relayPort !== relayPort) {
    panic('Error parsing ports.');
  }

  return [devicePort, relayPort];
}
206197
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
    """"""
    # We create a connected TCP socket. Note the trick with setblocking(0)
    # that prevents us from having to create a thread.
    lsock = socket.socket(family, type, proto)
    lsock.bind(('localhost', 0))
    lsock.listen(1)
    addr, port = lsock.getsockname()
    csock = socket.socket(family, type, proto)
    csock.setblocking(False)
    try:
        csock.connect((addr, port))
    except socket.error as e:
        if e.errno != errno.WSAEWOULDBLOCK:
            lsock.close()
            csock.close()
            raise
    ssock, _ = lsock.accept()
    csock.setblocking(True)
    lsock.close()
    return (ssock, csock)
334492
function SocketPeer (opts) {
  var self = this;

  if (!(self instanceof SocketPeer)) {
    return new SocketPeer(opts);
  }

  opts = opts || {};

  EventEmitter.call(self);

  self._connections = {
    socket: {success: 0, error: 0, attempt: 0},
    rtc: {success: 0, error: 0, attempt: 0}
  };
  self.peer = null;
  self.rtcConnected = false;
  self.socketConnected = false;

  extend(self, {
    pairCode: 'pairCode' in opts ? opts.pairCode : null,
    socketFallback: 'socketFallback' in opts ? opts.socketFallback : true,
    socket: 'socket' in opts ? opts.socket : null,
    stream: 'stream' in opts ? opts.stream : null,
    url: 'url' in opts ? opts.url : 'http://localhost',
    reconnect: 'reconnect' in opts ? opts.reconnect : true,
    reconnectDelay: 'reconnectDelay' in opts ? opts.reconnectDelay : 1000,
    timeout: 'timeout' in opts ? opts.timeout : 0,
    autoconnect: 'autoconnect' in opts ? opts.autoconnect : true,
    debug: 'debug' in opts ? opts.debug : false
  }, opts);

  self._debug('New peer');

  self.on('peer.found', function (data) {
    self.socketConnected = true;
    clearTimeout(self._socketConnectTimeout);
    clearTimeout(self._socketReconnectDelayTimeout);
    self._connections.socket.attempt = 0;
    self._connections.socket.success++;

    self.emit('connect');
    if (self._connections.socket.success > 0) {
      self.emit('reconnect');
    }

    self.initiator = data.initiator;

    if (data.initiator) {
      self._send('rtc.connect');
      self._rtcInit();
    }
  });
  self.on('rtc.signal', self._rtcSignal);
  self.on('rtc.connect', function () {
    self._rtcInit();
  });

  self.on('busy', function () {
    self._socketError(new Error('Pair code "' + self.pairCode + '" already in use'));
    self.socket.close();
  });

  if (self.autoconnect) {
    setTimeout(function () {
      self.connect();
    }, 0);
  }
}
554506
def add_port(self, port):
        
        self.ports.append(port)
        if port.io_type not in self.port_seqs:
            self.port_seqs[port.io_type] = 0
        self.port_seqs[port.io_type] += 1
        port.sequence = self.port_seqs[port.io_type]
        return self
17911
function init(space, socket) {  // {{{2
/**
 * Sends request to the master space to establish a link.
 *
 * @param space {Object} Slave space
 * @param ws {Object} WebSocket
 *
 * @method constructor
 */

  if (space.slaves) {
    if (socket._lid in space.slaves) {
      O.link.error(socket, O.log.todo('Duplicit lid', space, socket._lid));
      return;
    }
  } else {
    space.slaves = {};
  }

  this.space = space;
  space.slaves[socket._lid] = this;

  O.link.open(this, socket, {home: space.isAtHome() || space.masterState === space.MASTER_STATE.HOME})
  return;
}
662368
function connectServer(options, cb) {
    var socket = new net.Socket();
    var start = process.hrtime();

    socket.connect(options.port, options.address, function() {
        var time_arr = process.hrtime(start);
        var time = (time_arr[0] * 1e9 + time_arr[1]) / 1e6;
        results.push({
            seq:  count,
            time: time
        });
        try { socket.destroy(); } catch(e) {}
        count++;
        checkConnection(options, cb);
    });

    socket.on('error', function(e) {
        results.push({
            seq:  count,
            time: undefined,
            err:  e
        });
        try { socket.destroy(); } catch(e) {}
        count++;
        checkConnection(options, cb);
    });

    socket.setTimeout(options.timeout, function() {
        results.push({
            seq:  count,
            time: undefined,
            err:  Error('Request timeout')
        });
        try { socket.destroy(); } catch(e) {}
        count++;
        checkConnection(options, cb);
    });
}
1234221
function start () {
  if (!node) {
    const options = {
      EXPERIMENTAL: {
        pubsub: true
      },
      repo: 'ipfs-' + Math.random(),
      config: {
        Addresses: {
          Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
        }
      }
    }

    node = new IPFS(options)

    node.once('start', () => {
      node.id()
        .then((id) => {
          info = id
          updateView('ready', node)
          onSuccess('Node is ready.')
          setInterval(refreshPeerList, 1000)
          setInterval(sendFileList, 10000)
        })
        .catch((error) => onError(error))

      subscribeToWorkpsace()

      window.addEventListener('hashchange', workspaceUpdated)
    })
  }
}
1141801
def p_portlist_io(self, p):
        ''
        p[0] = Portlist(ports=p[2], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
873692
function nextPort(port) {
  if (!port) {
    return 8000;
  }

  //
  // Find the next port that we are not supposed to ignore or cause errors on
  //
  var unavailable = carapace.ports.ignore.concat(carapace.ports.throw);
  do {
    port = port + 1;
  } while (unavailable.indexOf(port) !== -1);

  return port;
}
101898
function init(options) {
  options = options || {}
  var port = options.port || 6466
  global.client = global.client || socketIOClient(`http://localhost:${port}`)
  client = global.client
  log.debug(`Started global js socketIO client for ${process.env.ADAPTER} at ${port}`)
  client.emit('join', ioid) // first join for serialization
  client.on('disconnect', client.disconnect)
  client.on('take', hasher.handle) // add listener
  
  // add methods
  client.pass = pass
  client.clientPass = clientPass
  return client
}
1182931
public Future<Void> start(final int port) {
        final ChannelFuture channelFuture = this.bootstrap.bind(port);
        this.allChannels.add(channelFuture.channel());

        return channelFuture;
    }
557330
def on_start(self, host, port, channel, nickname, password):
        
        self.client = WebSocketIRCClient(host, port, channel, nickname,
                                         password, self)
        self.spawn(self.client.start)
701321
public void start() throws IOException{
       remote_sock.setSoTimeout(iddleTimeout);
       client_sock.setSoTimeout(iddleTimeout);

       log("Starting UDP relay server on "+relayIP+":"+relayPort);
       log("Remote socket "+remote_sock.getLocalAddress()+":"+
                            remote_sock.getLocalPort());

       pipe_thread1 = new Thread(this,"pipe1");
       pipe_thread2 = new Thread(this,"pipe2");

       lastReadTime = System.currentTimeMillis();

       pipe_thread1.start();
       pipe_thread2.start();
    }
1291206
def start!(port) # @todo Support other handlers http://www.rubydoc.info/github/rack/rack/Rack/Handler
      Rack::Handler.get(WEBRICK).run(self, Port: port) do |s|
        @server = s
        at_exit { stop! }
        [:INT, :TERM].each do |signal|
          old = trap(signal) do
            stop!
            old.call if old.respond_to?(:call)
          end
        end
      end
    end
140301
function startBroker() {
	let worker = cluster.worker;

	if (worker) {
		Object.assign(config, {
			nodeID: (config.nodeID || utils.getNodeID()) + "-" + worker.id
		});
	}

	// Create service broker
	broker = new Moleculer.ServiceBroker(Object.assign({}, config));

	loadServices();

	return broker.start()
		.then(() => {
			if (flags.repl && (!worker || worker.id === 1))
				broker.repl();
		});
}
949886
function startServer(alerts, params, port, resources) {
    const compiledAlerts = compileMarkdown(alerts);
    const app = http.createServer((req, res) =>
        res.end(resources[req.url] || resources['/index.html']));
    const io = listen(app);
    io.on('connection', socket => {
        emitInfo(`new session for ${socket.handshake.address}`);
        socket.emit('update', compiledAlerts);
        socket.on('disconnect', () => {
            emitInfo(`disconnected session ${socket.handshake.address}`);
        });
    });

    return new Promise(resolve => app.listen(port, emitRungEmoji & resolve))
        .then(~watchChanges(io, params));
}