forked from bigeasy/udt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udt.js
32 lines (27 loc) · 906 Bytes
/
udt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const Server = require('./server')
, Socket = require('./socket')
, endpoint = require('./endpoint');
exports.createServer = function () {
return new Server();
};
exports.createConnection = function (port, host, connectListener) {
var socket = new Socket();
socket.on('connect', connectListener);
endpoint.createEndPoint({
port: 0
, address: '0.0.0.0'
}, onCreated);
function onCreated(endPoint) {
// We do this on the next tick so that execution
// runs out of this whole function and the user gets
// access to the unconnected socket. This allows them to set features
// on the socket such as timeout for handshaking the connection.
process.nextTick(() => {
socket.connect({
port: port
, address: host
}, endPoint);
});
}
return socket;
};