diff --git a/README.md b/README.md index f31d279..05c5714 100755 --- a/README.md +++ b/README.md @@ -91,6 +91,15 @@ finder.on('serverFound', function(server) { }) ``` +### constructor(port, address) + +Port is an integer. Address is an IPv4 address of the server as a string. + +Examples: +```javascript +var client = new ScreenLogic.UnitConnection(80, '10.0.0.85') +``` + ### connect() Connects to the server passed to its constructor. diff --git a/index.js b/index.js index 8aae029..954cf88 100644 --- a/index.js +++ b/index.js @@ -56,9 +56,15 @@ class FindUnits extends EventEmitter { } class UnitConnection extends EventEmitter { - constructor(server) { + constructor(server, address) { super(); - this.server = server; + if (typeof server === 'object') { + this.serverPort = server.port; + this.serverAddress = server.address; + } else { + this.serverPort = server; + this.serverAddress = address; + } this.client = new net.Socket(); var _this = this; @@ -76,7 +82,7 @@ class UnitConnection extends EventEmitter { connect() { //console.log("connecting..."); var _this = this; - this.client.connect(this.server.port, this.server.address, function() { + this.client.connect(this.serverPort, this.serverAddress, function() { _this.onConnected(); }); }