Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPv6 support #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $ npm install node-zookeeper-client
```javascript
var zookeeper = require('node-zookeeper-client');

// ipv6 : zookeeper.createClient('[2001:db8:65:6c61:622e:6b72:010:3214]:4322')
var client = zookeeper.createClient('localhost:2181');
var path = process.argv[2];

Expand Down
11 changes: 11 additions & 0 deletions lib/ConnectionStringParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ function ConnectionStringParser(connectionString) {
return item;
}).forEach(function (item) {
var parts = item.split(':');
var ipEndIndex = item.lastIndexOf(']');

if (parts.length > 2 && ipEndIndex !== -1) { // IPv6 (RFC 3986)
// not use endsWith (ECMAScript 6)
parts = [item.substring(1, ipEndIndex)];

// use port number
if (ipEndIndex !== (item.length - 1)) {
parts.push(item.substring(item.lastIndexOf(':') + 1));
}
}

servers.push({
host : parts[0],
Expand Down