agorushkin
agorushkin2w ago

Deno Datagram vs Node Datagram

When using the node default library in Deno, everything works fine, however, when using Deno's, I get os error 10051 A socket operation was attempted to an unreachable network
2 Replies
agorushkin
agorushkin2w ago
Node code
agorushkin
agorushkin2w ago
export class PromiseSocket {
#socket: Deno.DatagramConn;

constructor() {
this.#socket = Deno.listenDatagram({
port: 0,
transport: 'udp',
});
}

send = async (
buffer: Uint8Array,
host: string,
port: number,
): Promise<Result<Uint8Array>> => {
try {
const message_buffer = await this.#send(buffer, host, port);
return pass(message_buffer);
} catch (err) {
return fail(err);
}
};

close = () => {
this.#socket.close();
};

#send = async (
buffer: Uint8Array,
host: string,
port: number,
): Promise<Uint8Array> => {
const addr = {
hostname: host,
port,
transport: 'udp',
} satisfies Deno.NetAddr;

await this.#socket.send(buffer, addr);
const [message] = await this.#socket.receive();

return message;
};
}
export class PromiseSocket {
#socket: Deno.DatagramConn;

constructor() {
this.#socket = Deno.listenDatagram({
port: 0,
transport: 'udp',
});
}

send = async (
buffer: Uint8Array,
host: string,
port: number,
): Promise<Result<Uint8Array>> => {
try {
const message_buffer = await this.#send(buffer, host, port);
return pass(message_buffer);
} catch (err) {
return fail(err);
}
};

close = () => {
this.#socket.close();
};

#send = async (
buffer: Uint8Array,
host: string,
port: number,
): Promise<Uint8Array> => {
const addr = {
hostname: host,
port,
transport: 'udp',
} satisfies Deno.NetAddr;

await this.#socket.send(buffer, addr);
const [message] = await this.#socket.receive();

return message;
};
}
Deno code