MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / #send

Method #send

examples/io/udp/dns/dns.js:77–105  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

75 this.#timer ??= Timer.set(() => this.#task(), 0, 1000);
76 }
77 #send(request) {
78 const packet = new Serializer({query: true, recursionDesired: true, opcode: DNS.OPCODE.QUERY, id: request.id});
79 packet.add(DNS.SECTION.QUESTION, request.host, DNS.RR.A, DNS.CLASS.IN);
80
81 try {
82 this.#timer ??= Timer.repeat(() => this.#task(), 1000);
83
84 this.#socket ??= new (this.#UDP.io)({
85 target: this,
86 onReadable: function(count) {
87 while (count--)
88 this.target.#receive(this.read());
89 }
90 });
91
92 if (request.id) {
93 const servers = this.#servers;
94 this.#socket.write(packet.build(), servers[request.state % servers.length], 53);
95 }
96 else
97 this.#socket.write(packet.build(), "224.0.0.251", 5353);
98 }
99 catch {
100 if (!this.#timer) {
101 this.#remove(request);
102 request.onError?.call(this, request.host);
103 }
104 }
105 }
106 #receive(buffer) {
107 const packet = new Parser(buffer);
108 const question = packet.question(0);

Callers 1

#taskMethod · 0.95

Calls 8

addMethod · 0.95
#taskMethod · 0.95
buildMethod · 0.95
#removeMethod · 0.95
repeatMethod · 0.80
#receiveMethod · 0.80
readMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected