Home > front end >  Consult familiar with nodejs and CoAP, DTLS classmate
Consult familiar with nodejs and CoAP, DTLS classmate

Time:09-18

Want to secure communication using CoAP DTLS, this is the other bosses, the source of the down but no matter what happen to the server and client connection, seek a solution, there is something wrong with the certificate??
Server:
 const coap=the require (' coap)//or coap 
Const path=the require (" path ");

//var SegfaultHandler=the require (' segfault - handler ');

//SegfaultHandler. RegisterHandler (" crash log ");//With no argument, SegfaultHandler will generate a generic log file name

Const dtls_opts={
Key: the path. The join (__dirname, '../test/private. Der '),
The debug: 1,
HandshakeTimeoutMin: 3000
};


Const server=coap. CreateServer (
{
DTLS: dtls_opts,
Port: 5684,
}
);

Server on (' request ', function (the req, res) {
The console. The log (' request arrives: \ n '+ JSON. The stringify (the req));
Res. The end (' Hello '+ the req. Url. The split ('/') [1] +' \ n ')
})

Server. Listen (function () {
The console. The log (' server started ')
});

Client:
 var coap=the require (' coap)//or coap 


//var SegfaultHandler=the require (' segfault - handler ');

//SegfaultHandler. RegisterHandler (" crash log ");//With no argument, SegfaultHandler will generate a generic log file name

Var dtls_opts={
//PSK: new Buffer (' AAAAAAAAAAAAAAAA),
//PSKIdent: new Buffer (" 32323232-3232-3232-3232-323232323232),
PSK: Buffer. The from (" AAAAAAAAAAAAAAAA "),
PSKIdent: Buffer. The from (" 32323232-3232-3232-3232-323232323232),
Key: null,
PeerPublicKey: null
};

Var the req=coap. Request (' coaps://127.0.0.1:5684/client ',
Dtls_opts,
(the req)=& gt; {
The req. On (' response ', function (res) {
Res. Pipe (process. Stdout)
});
The req. End ();
}
);

  • Related