Node-CoAP: Difference between revisions
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
==Exemple 1== |
==Exemple 1== |
||
Modifiez l'exemple server.js |
|||
<source lang="javascript"> |
|||
const coap = require('coap') |
|||
, server = coap.createServer() |
|||
server.on('request', function(req, res) { |
|||
console.log('Request:'+JSON.stringify(req, null, '\t')); |
|||
res.end('Hello ' + req.url.split('/')[1] + '\n') |
|||
}) |
|||
server.listen(function() { |
|||
console.log('server started') |
|||
}) |
|||
</source> |
|||
Sur Term 1 |
Sur Term 1 |
||
<source lang="bash"> |
<source lang="bash"> |
Revision as of 14:53, 19 October 2014
Bibliothèque Node.js pour des services CoAP
https://github.com/mcollina/node-coap
Installation
npm install coap
sudo npm install coap-cli -g
coap --help
git clone https://github.com/mcollina/node-coap.git
cd node-coap-master/examples
Lancement du serveur
Exemple 1
Modifiez l'exemple server.js
const coap = require('coap')
, server = coap.createServer()
server.on('request', function(req, res) {
console.log('Request:'+JSON.stringify(req, null, '\t'));
res.end('Hello ' + req.url.split('/')[1] + '\n')
})
server.listen(function() {
console.log('server started')
})
Sur Term 1
node server.js
Sur Term 2
node client.js
coap get coap://localhost/bla
Vous pouvez également envoyer des requêtes GET et POST en utilisant le plugin Copper de Firefox
Exemple 2
Sur Term 1
node observe_server.js
Sur Term 2
node observe_client.js
coap observe coap://localhost/bla
Vous pouvez également envoyer des requêtes OBSERVE en utilisant le plugin Copper de Firefox