Creates and binds the Socket.

@return void
438251
public function connect()
    {
        $socket = $this->createSocket(
            $this->connection->getHostname(),
            $this->connection->getPort(),
            $this->throttle
        );

        $this->setSocket($socket);
    }
361685
protected function connect()
    {
        $errstr = '';
        $errno  = 0;

        $this->log('creating socket ... ', Net_Notifier_Logger::VERBOSITY_ALL);

        try {
            $this->socket = new Net_Notifier_Socket_Server(
                sprintf(
                    'tcp://0.0.0.0:%s',
                    $this->port
                ),
                null
            );
        } catch (Net_Notifier_Socket_Exception $e) {
            $this->log(
                'failed' . PHP_EOL,
                Net_Notifier_Logger::VERBOSITY_ALL,
                false
            );
            throw $e;
        }

        $this->log('done' . PHP_EOL, Net_Notifier_Logger::VERBOSITY_ALL, false);

        $this->connected = true;
    }
1058455
protected function bindRoom(): void
    {
        $this->app->bind(RoomContract::class, function (App $app) {
            $config = $app->make('config');
            $room   = $config->get('swoole.websocket.room', []);

            $className = Arr::pull($room, 'type', TableRoom::class);

            // create room instance and initialize
            $room = $this->createRoom($className, $room);
            $room->prepare();

            return $room;
        });

        $this->app->bind('swoole.room', RoomContract::class);
    }
186119
public function run(): void
    {
        pcntl_async_signals(true);

        $this->makeSocket();

        [$pid, $master, $workers] = $this->spawn();

        if ($pid) {
            fclose($this->socket);
            $this->workerPids = $workers;
            $this->handleSignals();

            (new Master($workers, $this->unixConnector, $this->exchangeWorkersData))->dispatch();
        } else {
            if ($this->useConnector) {
                fclose($this->unixConnector);
            }

            (new $this->handler($this->socket, $master))->handle();
        }
    }
498437
public function initialize()
    {
        try {
            $this->logger->debug('Connecting to the websocket');
            $this->engine->connect();
            $this->logger->debug('Connected to the server');

            $this->isConnected = true;
        } catch (SocketException $e) {
            $this->logger->error('Could not connect to the server', ['exception' => $e]);

            throw $e;
        }

        return $this;
    }
777019
public function connect()
    {
        Debug::Log(Debug::DEBUG, 'socket_connect()');
        if (!$this->context) {
            $context = stream_context_create();
        } else {
            $context = $this->context;
        }
        Debug::Log(Debug::DEBUG, 'socket_connect(): connect to='.$this->address);

        $this->socket = stream_socket_client(
            $this->address,
            $errno,
            $errstr,
            60,
            STREAM_CLIENT_CONNECT,
            $context
        );
        if (!$this->socket) {
            Debug::Log(Debug::DEBUG, "stream_socket_client() {$errno}, {$errstr}");
            return false;
        }
        stream_set_timeout($this->socket,  5);

        #TODO:  MUST BE IN BLOCKING MODE
        #$this->set_blocking();

        return true;
    }
682126
public function bindSocket()
    {
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
        if (!$sock) {
            $errno = socket_last_error();
            Daemon::$process->log(get_class($this) . ': Couldn\'t create UDP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
            return false;
        }
        if (!isset($this->port)) {
            if (isset($this->defaultPort)) {
                $this->port = $this->defaultPort;
            } else {
                Daemon::log(get_class($this) . ' (' . get_class($this->pool) . '): no port defined for \'' . $this->uri['uri'] . '\'');
            }
        }
        if ($this->reuse) {
            if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
                $errno = socket_last_error();
                Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEADDR to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
                return false;
            }
            if (defined('SO_REUSEPORT') && !@socket_set_option($sock, SOL_SOCKET, SO_REUSEPORT, 1)) {
                $errno = socket_last_error();
                Daemon::$process->log(get_class($this) . ': Couldn\'t set option REUSEPORT to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
                return false;
            }
        }
        if (!@socket_bind($sock, $this->host, $this->port)) {
            $errno = socket_last_error();
            $addr = $this->host . ':' . $this->port;
            Daemon::$process->log(get_class($this) . ': Couldn\'t bind UDP-socket \'' . $addr . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').');
            return false;
        }
        socket_getsockname($sock, $this->host, $this->port);
        $addr = $this->host . ':' . $this->port;
        socket_set_nonblock($sock);
        $this->setFd($sock);
        return true;
    }
905413
protected function prepareWebsocket()
    {
        $config = $this->container->make('config');
        $isWebsocket = $config->get('swoole_http.websocket.enabled');
        $parser = $config->get('swoole_websocket.parser');

        if ($isWebsocket) {
            $this->events = array_merge($this->events ?? [], $this->wsEvents);
            $this->isServerWebsocket = true;
            $this->setPayloadParser(new $parser);
        }
    }
1163897
private void initSocket() {
    socket = new Socket();
    try {
      socket.setSoLinger(false, 0);
      socket.setTcpNoDelay(true);
      socket.setSoTimeout(timeout);
    } catch (SocketException sx) {
      LOGGER.error("Could not configure socket.", sx);
    }
  }
431175
private function acceptConnection(): void
    {
        $clientSocket = @stream_socket_accept($this->serverSocket);

        if (false !== $clientSocket) {
            stream_set_blocking($clientSocket, false);

            $connection = new StreamSocketConnection($clientSocket);

            $id = spl_object_hash($connection);

            $this->clientSockets[$id] = $clientSocket;
            $this->connections[$id]   = $connection;
        }
    }
1177429
private function connect()
    {
        if (!$this->socket->isOpened()) {
            $this->socket->open();

            if ($this->secret) {
                $this->socket->send(join(Driver::SEP, ['A', 1, Driver::encode($this->secret)]).Driver::EOL);
            }
        }
    }
529066
public function bindSocket()
    {
        if ($this->erroneous) {
            return false;
        }
        $port = $this->getPort();
        if (!is_int($port)) {
            Daemon::log(get_class($this) . ' (' . get_class($this->pool) . '): no port defined for \'' . $this->uri['uri'] . '\'');
            return;
        }
        if (($port < 1024) && Daemon::$config->user->value !== 'root') {
            $this->listenerMode = false;
        }
        if ($this->listenerMode) {
            $this->setFd($this->host . ':' . $port);
            return true;
        }
        $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if (!$sock) {
            $errno = socket_last_error();
            Daemon::$process->log(get_class($this->pool) . ': Couldn\'t create TCP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
            return false;
        }
        if ($this->reuse) {
            if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
                $errno = socket_last_error();
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t set option REUSEADDR to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
                return false;
            }
            if (defined('SO_REUSEPORT') && !@socket_set_option($sock, SOL_SOCKET, SO_REUSEPORT, 1)) {
                $errno = socket_last_error();
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t set option REUSEPORT to socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
                return false;
            }
        }
        if (!@socket_bind($sock, $this->host, $port)) {
            $errno = socket_last_error();
            Daemon::$process->log(get_class($this->pool) . ': Couldn\'t bind TCP-socket \'' . $this->host . ':' . $port . '\' (' . $errno . ' - ' . socket_strerror($errno) . ').');
            return false;
        }
        socket_getsockname($sock, $this->host, $this->port);
        socket_set_nonblock($sock);
        if (!$this->listenerMode) {
            if (!socket_listen($sock, SOMAXCONN)) {
                $errno = socket_last_error();
                Daemon::$process->log(get_class($this->pool) . ': Couldn\'t listen TCP-socket \'' . $this->host . ':' . $port . '\' (' . $errno . ' - ' . socket_strerror($errno) . ')');
                return false;
            }
        }
        $this->setFd($sock);
        return true;
    }
677021
public function handleConnect()
    {
        $socket = @stream_socket_accept($this->socket);

        if ($socket === false)
        {
            $this->emit('error', [ $this, new ReadException('Socket could not accept new connection.') ]);
            return;
        }

        $client = null;
        $ex = null;

        try
        {
            $client = $this->createClient($socket, [
                'ssl' => $this->config['ssl'],
                'ssl_method' => $this->config['ssl_method'],
            ]);

            $this->emit('connect', [ $this, $client ]);
        }
        catch (Error $ex)
        {}
        catch (Exception $ex)
        {}

        if ($ex !== null)
        {
            $this->handleDisconnect($socket);
            $this->emit('error', [ $this, new ReadException('Socket could not wrap new connection!') ]);
        }
    }
926853
def server_bind(self):
        

        if self.allow_reuse_address:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(self.server_address)
1374250
private function initWebsocketServer()
    {
        $websocketBind = $this->sandstoneApplication['sandstone.websocket.server']['bind'];
        $websocketPort = $this->sandstoneApplication['sandstone.websocket.server']['port'];

        $socket = new ReactSocketServer("$websocketBind:$websocketPort", $this->loop);

        new IoServer(
            new HttpServer(
                new WsServer(
                    new ServerProtocol(
                        new WebsocketApplication(
                            $this->sandstoneApplication
                        )
                    )
                )
            ),
            $socket
        );
    }
777851
public function connect()
  {
    if($this->stream !== null) return;

    $host     = strval($this->config["host"]);
    $port     = strval($this->config["port"]);
    $timeout  = intval($this->config["timeout"]);
    $blocking = intval($this->config["blocking"]);

    if(empty($this->config["ssh"]))
    {
      $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
      $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));

      $this->stream = @stream_socket_client($address, $errno, $errstr, $this->config["timeout"], STREAM_CLIENT_CONNECT, stream_context_create($options));

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
      }

      if(!empty($this->config["tls"]))
      {
        stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
      }
    }
    else
    {
      $this->session = @ssh2_connect($host, $port);

      if($this->session === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to establish secure shell connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }

      if(!@ssh2_auth_password($this->session, $this->config["username"], $this->config["password"]))
      {
        throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid loginname or password", 0x208);
      }

      $this->stream = @ssh2_shell($this->session, "raw");

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to open a secure shell on server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }
    }

    @stream_set_timeout($this->stream, $timeout);
    @stream_set_blocking($this->stream, $blocking ? 1 : 0);
  }
956423
protected function createReplySocket()
    {
        $replyContext = new \ZMQContext;
        $this->replySocket = $replyContext->getSocket(\ZMQ::SOCKET_REQ);
        $this->replySocket->connect($this->config['sockets']['worker_reply']);
    }