protected static function initSocket($scheme, $host, $port, array $context)
    {
        $socketDescriptor = sprintf("%s://%s:%d", $scheme, $host, $port);
        $socket = @stream_socket_client(
            $socketDescriptor,
            $errNo,
            $errStr,
            static::SOCKET_TIMEOUT,
            \STREAM_CLIENT_CONNECT,
            stream_context_create($context)
        );

        if ($socket === false) {
            throw new RuntimeException(
                sprintf(
                    "Failed to create socket-client for %s: %s (%s)",
                    $socketDescriptor,
                    $errStr,
                    $errNo
                )
            );
        }

        // set non-blocking for UDP
        if (strcasecmp("udp", $scheme) == 0) {
            stream_set_blocking($socket, 0);
        }

        return $socket;
    }