Installation and testing of COAP protocol under Linux environment

Source: Internet
Author: User
Tags install node npm install node

Recently in contact with the COAP protocol, an Internet of things protocol dedicated to restricted devices, downloaded its source code and wanted to install it under Linux. And because of the many programming languages, try Python and nodejs for the moment.


Python source Download

In the readme.md file, the installation method has been introduced very well, but in the implementation of the sudo pip install dist/coapthon-2.0.0.tar.gz-r requirements.txt when prompted missing Python.h header file, so it is known that the development package is not an Ann, so the installation Python2.7-dev

By default, the relevant executables and Coap Python libraries are in the/usr/local directory, such as coapserver.py,coapclient.py under Bin

Python Simple test

Execute the coapserver.py directly at the terminal:


Perform coapclient.py on another terminal:


At this point, the server has the following output:


Obviously, the service has received the customer's request, all have the relevant output. Since it is only a test and is not familiar with the relevant APIs, only visual results can be obtained.

If you use a browser as the client, that is, enter the domain name, click the Get command, under incoming, there is output, as shown:



JS Source Download

After downloading, the folder name is Node-coap and the command is executed:

sudo npm install Node-coap--save

Can see a lot of things output, with NPM ls (to be executed in the NPM install directory) command to verify the installed

JS Simple test

1, enter the Node-coap/examples directory, modify the Server.js

Const COAP    = require (' Coap ')     , server  = Coap.createserver () server.on (' Request ', function (req, res) {  Res.end (' Hello ' + req.url.split ('/') [1] + ' \ n ')}) Server.listen (function () {  console.log (' Server Started ')})

Modify Client.js

Const COAP  = require (' Coap ')     , req   = coap.request (' Coap://localhost/cshi ') req.on (' response ', function ( RES) {  res.pipe (process.stdout)}) Req.end ()

2. Implementation

Service side: Nodejs Server.js & (running in the background)

Client: Nodejs client.js


Firefox browser test (need to install copper plug-in, Firefox official, if not bring your own)


That is, after the client sends a request to the server, the server loopback Hello Cshi


We can also use the command-line tool to perform client simulations. Download NODE-CLI

sudo npm install node-cli-g (be sure to add-g)

As a result, relevant files, such as executables, are generated in/usr/local bin and Lib/node_modules Coap

Execution: Coap get Coap://localhost/cshi


The above two are all installed, NPM LS displays as follows:


Reference links

NPM Install usage: http://blog.csdn.net/haidaochen/article/details/8546796

Node-coap Tutorial: http://blog.csdn.net/xukai871105/article/details/39213061

Installation and testing of COAP protocol under Linux environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.