public function connect(ZMQSocket $socket, $mode, $dsn)
    {
        if ($mode == self::MODE_CONSTRUCT) {
            return $this;
        }

        $func = null;
        if ($mode == self::MODE_BIND) {
            $func = 'bind';
        } elseif ($mode == self::MODE_CONNECT) {
            $func = 'connect';
        }

        if (is_string($dsn)) {
            $dsn = array($dsn);
        }

        if (!is_array($dsn)) {
            throw new \RuntimeException('DSN should be a string or an array.');
        }

        foreach ($dsn as $d) {
            if (!is_string($d)) {
                throw new \RuntimeException('Non-string in DSN array detected.');
            }
            $socket->$func($d);
        }
    }