diff --git a/src/DNode/DNode.php b/src/DNode/DNode.php index bd76131..4566b2d 100644 --- a/src/DNode/DNode.php +++ b/src/DNode/DNode.php @@ -30,15 +30,22 @@ public function using($middleware) public function connect() { $params = $this->protocol->parseArgs(func_get_args()); - if (!isset($params['host'])) { - $params['host'] = '127.0.0.1'; + + if (isset($params['path'])) { + $client = @stream_socket_client("unix://{$params['path']}"); } - - if (!isset($params['port'])) { - throw new \Exception("For now we only support TCP connections to a defined port"); + else { + if (!isset($params['host'])) { + $params['host'] = '127.0.0.1'; + } + + if (!isset($params['port'])) { + throw new \Exception("For now we only support TCP connections to a defined port"); + } + + $client = @stream_socket_client("tcp://{$params['host']}:{$params['port']}"); } - - $client = @stream_socket_client("tcp://{$params['host']}:{$params['port']}"); + if (!$client) { $e = new \RuntimeException("No connection to DNode server in tcp://{$params['host']}:{$params['port']}"); $this->emit('error', array($e));