Added ability to connect by address and port
This commit is contained in:
@ -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()
|
### connect()
|
||||||
|
|
||||||
Connects to the server passed to its constructor.
|
Connects to the server passed to its constructor.
|
||||||
|
12
index.js
12
index.js
@ -56,9 +56,15 @@ class FindUnits extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UnitConnection extends EventEmitter {
|
class UnitConnection extends EventEmitter {
|
||||||
constructor(server) {
|
constructor(server, address) {
|
||||||
super();
|
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();
|
this.client = new net.Socket();
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@ -76,7 +82,7 @@ class UnitConnection extends EventEmitter {
|
|||||||
connect() {
|
connect() {
|
||||||
//console.log("connecting...");
|
//console.log("connecting...");
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.client.connect(this.server.port, this.server.address, function() {
|
this.client.connect(this.serverPort, this.serverAddress, function() {
|
||||||
_this.onConnected();
|
_this.onConnected();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user