-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPSocketServer.js
More file actions
59 lines (59 loc) · 1.66 KB
/
UDPSocketServer.js
File metadata and controls
59 lines (59 loc) · 1.66 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}),
exports.UDPSocketServer = void 0;
var tslib_1 = require("tslib"),
EventEmitterImpl = require("./EventEmitter").EventEmitter,
noop = require("./util").noop,
UDPSocketServer = function(e) {
function t(t, o, i) {
var r = e.call(this) || this;
return r.TAG = "UDPSocketServer",
r.msgHandler = noop,
r.mSocket = t,
r.isClose = !1,
r.mSocket.onClose((function() {
r.interrupt()
})),
r.mTimeout = o,
i && (r.mCorrectLen = i),
r
}
return tslib_1.__extends(t, e),
t.prototype.startServer = function() {
this.handlerTimeout(this.mTimeout),
this.onListening(),
this.onMessage(this.mCorrectLen)
},
t.prototype.handlerTimeout = function(e) {
var t = this;
this.mSocketTimeoutTimer = setTimeout((function() {
t.trigger("timeout"),
t.interrupt()
}), e)
},
t.prototype.onMessage = function(e) {
var t = this;
this.msgHandler = function(o) {
t.isClose || (console.log(t.TAG, "recieveMsg", o), t.trigger("recieveMsg", o), !e || e && o.remoteInfo.size === e ? t.trigger("recieveCorrectMsg", o) : console.log(t.TAG, "received len is different from specific len"))
},
this.mSocket.onMessage(this.msgHandler)
},
t.prototype.onListening = function() {
var e = this;
this.mSocket.onListening((function(t) {
e.isClose || (e.trigger("recieveMsg", t), console.log(e.TAG, "onListening", t))
}))
},
t.prototype.interrupt = function() {
console.log(this.TAG, "USPSocketServer is interrupt"),
this.mSocket.offMessage(this.msgHandler),
this.close()
},
t.prototype.close = function() {
this.isClose = !0
},
t
} (EventEmitterImpl);
exports.UDPSocketServer = UDPSocketServer;