Create the socket server. Binds and listens on a specific port

@param string $ip
@param int $port
@param array $options
@return $this
@throws ConnectionException
14135
public static function bind(string $ip, int $port, array $options = []) : SocketServer
    {
        return (new self($options))->listen($ip, $port);
    }
167127
private static function createSocket($host, $port, $sendTimeout, $receiveTimeout)
    {
        $socket = new TSocket($host, $port, true);
        if (null !== $sendTimeout) {
            $socket->setSendTimeout($sendTimeout);
        }

        if (null !== $receiveTimeout) {
            $socket->setRecvTimeout($receiveTimeout);
        }

        return $socket;
    }
1025707
public function connectToServer($address, $options = array())
	{
		$parameters = NULL;

		if ( array_key_exists('port', $options) )
		{
			$parameters = ':'.$options['port'];
		}
		if ( array_key_exists('password', $options) )
		{
			$parameters .= '/'.$options['password'];
		}		
		return $this->protocol.'connect/'.$address.$parameters;
	}
628687
public function createServer(int $port = 80) : Server
    {
        $listenIPv4 = new Directive('listen', [new Param($port)]);
        $listenIPv6 = new Directive('listen', [new Param("[::]:{$port}"), new Param('default'), new Param('ipv6only=on')]);

        return new Server([$listenIPv4, $listenIPv6]);
    }
486652
public function listen(): void
    {
        $this->socket = stream_socket_server(
            $this->getUri(),
            $errno,
            $errstr,
            STREAM_SERVER_BIND | STREAM_SERVER_LISTEN,
            $this->getStreamContext()
        );

        if (!$this->socket) {
            throw new ConnectionException(sprintf(
                'Could not listen on socket: %s (%d)',
                $errstr,
                $errno
            ));
        }

        $this->listening = true;
    }
1268606
public static function udp(string $host, array $options = []) : Socket
    {
        return self::create($host, \array_merge($options, [
            'transport' => 'udp',
            'buffer_size' => 65507,
        ]));
    }
1184530
public function listen($port, $host = '0.0.0.0')
    {
        $this->port = $port;
        $this->host = $host;
        
        return $this;
    }
98135
public function bind(InetAddress $addr, $port = 0)
    {
        if (@socket_bind($this->socket, $addr->getHostAddress(), $port) === false) {
            $this->throwSocketError();
        }
    }
1076777
public function connect($address, $port = 0)
    {
        try {
            socket_connect($this->socket, $address, $port);
        } catch (\Exception $e) {
            throw new CreateSocketException($e->getMessage());
        }
    }
1206564
public function getAMQPConnection(array $options)
    {
        if (!class_exists(AMQPStreamConnection::class)) {
            throw new \DomainException('Please install php-amqplib/php-amqplib first.');
        }

        $defaultOptions = [
            'host' => 'localhost',
            'port' => 5672,
            'user' => 'guest',
            'password' => 'guest',
        ];

        $options = array_merge($defaultOptions, $options);

        return new AMQPStreamConnection(
            $options['host'],
            $options['port'],
            $options['user'],
            $options['password']
        );
    }
250777
public function listen($port, $host = "127.0.0.1")
    {
        $runner = new Runner($this);
        $runner->listen($port, $host);

        return $this;
    }
710097
public function defaultCommand($ip = '127.0.0.1', $port = 1983)
    {
        $router_str = <<<'STR'
<?php
$_SERVER['SERVER_ADDR'] = ':ip';
$_SERVER['SERVER_PORT'] = ':port';
$_SERVER['REQUEST_SCHEME'] = 'http';
chdir('public');
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if ($uri !== '/') {
    if (file_exists('public/' . $uri)
        || preg_match('#\.(?:css|js|gif|png|jpg|jpeg|ttf|woff|ico)$#', $uri) === 1
    ) {
        return false;
    }
}

$_GET['_url'] = $uri;
$_REQUEST['_url'] = $uri;
require_once  'index.php';
STR;

        if ($value = $this->arguments->getValue(0)) {
            if (strpos($value, ':')) {
                list($ip, $port) = explode(':', $value, 2);
            } elseif (is_numeric($value)) {
                $port = (int)$value;
            } else {
                $ip = $value;
            }
        }
        $router = 'builtin_server_router.php';
        $this->filesystem->filePut("@tmp/$router", strtr($router_str, [':ip' => $ip, ':port' => $port]));

        echo "server listen on: $ip:$port", PHP_EOL;

        $prefix = $this->router->getPrefix();
        if (DIRECTORY_SEPARATOR === '\\') {
            shell_exec("explorer.exe http://$ip:$port" . $prefix);
        }

        shell_exec("php -S $ip:$port -t public tmp/$router");
    }
1294801
public function listen(string $ip, int $port)
    {
        $flags = STREAM_SERVER_BIND;
        if ($this->options['transport'] !== 'udp') {
            $flags |= STREAM_SERVER_LISTEN;
        }
        $this->socket = @\stream_socket_server(
            $this->options['transport'].'://'.$ip.':'.$port,
            $this->errorNumber,
            $this->errorMessage,
            $flags,
            $this->createSocketContext()
        );
        if (!$this->socket) {
            throw new ConnectionException(sprintf(
                'Unable to open %s socket (%s): %s',
                \strtoupper($this->options['transport']),
                $this->errorNumber,
                $this->errorMessage
            ));
        }

        return $this;
    }
556355
public function set($transport, $ip, $port, $timeout = 3, $blocking = false)
    {

        $this->transport = $transport;

        $this->ip = $ip;

        $this->port = $port;

        $this->timeout = $timeout;

        $this->blocking = $blocking;
    }
402890
public function connect(array $servers, $connectionId = null, array $options = [], array $credentials = [])
    {
        $memcached = $this->getMemcached(
            $connectionId, $credentials, $options
        );

        if (! $memcached->getServerList()) {
            // For each server in the array, we'll just extract the configuration and add
            // the server to the Memcached connection. Once we have added all of these
            // servers we'll verify the connection is successful and return it back.
            foreach ($servers as $server) {
                $memcached->addServer(
                    $server['host'], $server['port'], $server['weight']
                );
            }
        }

        return $this->validateConnection($memcached);
    }
261813
public function setIP($ip)
    {
        if (!filter_var($ip, FILTER_VALIDATE_IP)) {
            throw new InvalidArgumentException("Invalid ip $ip");
        }
        $this->ip = $ip;
        return $this;
    }
1307741
function Server(server, options)
{
	events.EventEmitter.call(this);
	
	this.listen = function(options, callback) {
		server.listen(options, callback);
	};
	
	server.on('connection', (socket) => {
		options = options || {};
		options.isServer = true;
		this.emit('client', new Client(socket, options));
	});
}