How to use node-dtls-client - 4 common examples

To help you get started, we’ve selected a few node-dtls-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlCalzone / node-coap-client / build / CoapClient.js View on Github external
port: origin.port,
                }, CoapClient.dtlsParams.get(origin.hostname));
                // return a promise we resolve as soon as the connection is secured
                const ret = DeferredPromise_1.createDeferredPromise();
                // try connecting
                const onConnection = () => {
                    debug("successfully created socket for origin " + origin.toString());
                    sock.removeListener("error", onError);
                    ret.resolve(new SocketWrapper_1.SocketWrapper(sock));
                };
                const onError = (e) => {
                    debug("socket creation for origin " + origin.toString() + " failed: " + e);
                    sock.removeListener("connected", onConnection);
                    ret.reject(e.message);
                };
                const sock = node_dtls_client_1.dtls
                    .createSocket(dtlsOpts)
                    .once("connected", onConnection)
                    .once("error", onError);
                return ret;
            default:
                throw new Error(`protocol type "${origin.protocol}" is not supported`);
        }
    }
}
github AlCalzone / node-coap-client / src / CoapClient.ts View on Github external
// return a promise we resolve as soon as the connection is secured
				const ret = createDeferredPromise();

				// try connecting
				const onConnection = () => {
					debug("successfully created socket for origin " + origin.toString());
					sock.removeListener("error", onError);
					ret.resolve(new SocketWrapper(sock));
				};
				const onError = (e: Error) => {
					debug("socket creation for origin " + origin.toString() + " failed: " + e);
					sock.removeListener("connected", onConnection);
					ret.reject(e.message);
				};
				const sock = dtls
					.createSocket(dtlsOpts)
					.once("connected", onConnection)
					.once("error", onError)
					;
				return ret;
			default:
				throw new Error(`protocol type "${origin.protocol}" is not supported`);
		}

	}
github AlCalzone / node-coap-client / build / lib / SocketWrapper.js View on Github external
constructor(socket) {
        super();
        this.socket = socket;
        this.isDtls = (socket instanceof node_dtls_client_1.dtls.Socket);
        socket
            .on("message", (message, rinfo) => {
            this.emit("message", message, rinfo);
        })
            .on("error", (err) => {
            this.emit("error", err);
        })
            .on("close", () => {
            this.emit("close");
        });
    }
    send(msg, origin) {
github AlCalzone / node-coap-client / src / lib / SocketWrapper.ts View on Github external
constructor(public socket: dtls.Socket | dgram.Socket) {
		super();
		this.isDtls = (socket instanceof dtls.Socket);
		(socket as any)
			.on("message", (message: Buffer, rinfo: dgram.RemoteInfo) => {
				this.emit("message", message, rinfo);
			})
			.on("error", (err: Error) => {
				this.emit("error", err);
			})
			.on("close", () => {
				this.emit("close");
			})
			;
	}

node-dtls-client

DTLS protocol implementation for Node.js written in TypeScript.

MIT
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis