Raspberry Pi & Node.js & WebSockets & IM
Raspberry Pi & Node.js & WebSockets & IM
Raspberry Pi 4
nvm & node.js
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
$ command -v nvm
# v12.1.0
$ nvm install node
# LTS v10.15.3
# LTS v10.16.0
$ nvm install 10.16.0
$ nvm ls-remote
$ nvm use node
# OR
$ nvm run node --version
$ node -v
$ npm -v
https://www.cnblogs.com/xgqfrms/p/10825908.html
https://github.com/nvm-sh/nvm#install--update-script
https://github.com/nvm-sh/nvm/releases



dubnium

chmod
linux & chmod 777 & chmod +x
https://www.cnblogs.com/xgqfrms/p/9546961.html
https://www.cnblogs.com/xgqfrms/p/9551553.html
https://www.cnblogs.com/xgqfrms/p/9626636.html
https://github.com/xgqfrms-GitHub/Node-CLI-Tools/blob/master/bash-shell-chmod.md
#!/bin/sh
# echo "^-v-^ JSON DB is running in development env!" && npm run db
# echo "^-v-^ JSON DB is running in development env!" && nodemon -w ./server.js localhost 8888
JSONDB="nodemon -w ./server.js localhost 8888"
${JSONDB} &
# chmod +x db.sh
# OR
# chmod 777 db.sh
# sudo ./db.sh
# nodemon -w ./server.js localhost 8888
# /bin/sh db.sh
# ps -ef | grep node
# sudo kill -9 <PID>
IM server in js
node.js chat application tutorial
https://socket.io/get-started/chat
https://itnext.io/build-a-group-chat-app-in-30-lines-using-node-js-15bfe7a2417b
https://www.freecodecamp.org/news/building-a-chat-application-with-mean-stack-637254d1136d/
https://www.cnblogs.com/baby123/p/6564168.html
https://hapijs.com/tutorials?lang=zh_CN
https://hapijs.com/api
OK

$ npm i ws
# OR
$ yarn add ws
$ npm i -g app-node-env
# OR
$ yarn global add app-node-env
$ npm link
ws client
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description WS client
* @augments
* @example
* @link
*
*/
const url = `ws://192.168.1.36:8888/`;
let ws = new WebSocket(url);
let log = console.log;
ws.onopen = function(e) {
log(`已经建立连接 open`, ws.readyState);
log(`e = `, e);
};
ws.onerror = function(e) {
log(`连接异常 error`, ws.readyState);
log(`e = `, e);
};
ws.onmessage = function(res) {
log(`收到消息 message`, ws.readyState);
let data = res.data;
let origin = res.origin;
log(`res & e = `, res);
log(`res.data = `, JSON.stringify(data, null, 4));
log(`res.origin = `, origin);
};
ws.onclose = function(e) {
log(`已经关闭连接 close`, ws.readyState);
log(`e = `, e);
};
setTimeout(() => {
ws.onopen = function(e) {
log(`已经建立连接 open`, ws.readyState);
log(`e = `, e);
};
}, 1000 * 1);
// setTimeout(() => {
// ws.send(`hello server!`);
// }, 3000);
let flag = setInterval(() => {
ws.send(`hello server!`);
}, 3000);
setTimeout(() => {
clearInterval(flag);
}, 60 * 1000);
ws server
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description WS server
* @augments
* @example
* @link
*
*/
const WebSocket = require('ws');
const wss = new WebSocket.Server({
// host: "",
// path: "",
port: 8888
});
let counter = 1;
wss.on('connection', function (ws, req) {
console.log("client connected", counter);
counter ++;
ws.on("message", function (msg) {
console.log(`receive message = `, msg);
if (ws.readyState === 1) {
const json = {
"success": true,
"message": null,
"data": [
{
"pro_name": "otc",
"pro_instructions": null,
"pro_type_name": "front-end",
"send_time": null,
"incre": true,
},
{
"pro_name": "ds",
"pro_instructions": null,
"pro_type_name": "back-end",
"send_time": null,
"incre": false
}
]
};
// const json = {
// success: true,
// message: "success",
// data: []
// };
let datas = JSON.stringify(json);
// return json datas;
ws.send(datas);
// ws.send("server returned message!");
}
});
let ip = req.connection.remoteAddress;
console.log(`ip =`, ip);
// push message ??? server
});
chmod 777

https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=chmod
refs
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
Raspberry Pi & Node.js & WebSockets & IM的更多相关文章
- Node.js + Web Socket 打造即时聊天程序嗨聊
前端一直是一块充满惊喜的土地,不仅是那些富有创造性的页面,还有那些惊赞的效果及不断推出的新技术.像node.js这样的后端开拓者直接将前端人员的能力扩大到了后端.瞬间就有了一统天下的感觉,来往穿梭于前 ...
- Node.js 学习资源
这篇文章编译整理自Stack Overflow的一个如何开始学习Node.js的Wiki帖,这份资源列表在SO上面浏览接近60万次,数千个收藏和顶.特意整理发布到这里,其中添加了部分中文参考资料. 学 ...
- Hello Raspberry Pi
Raspberry Pi 入手好一段时间了,原意是想撸 linux,但是后来一整年都在忙孩子房子户口本子的事,这玩意也就搁了一年尘. 最近终于被生活折腾到了尾声,开始找一些东西来折腾折腾. 一.什么是 ...
- 用Node.js开发Windows 10物联网应用
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 未来10年内,物联网将会如移动互联网这样深入到我们生活的各方各面.所以微软现在对物联网进行了 ...
- 34 个使用 Raspberry Pi 的酷创意
如果你手头有一个 Raspberry Pi(树莓派),你会拿它来做什么?或许以下 34 个如何使用 Raspberry Pi 的创意能够给你带来一些启发. Web 服务器 家庭自动化 BitTorre ...
- [Cubieboard] 在 Cubieboard 上安装 Node.js 和 npm
你有两个选择可以实现在Cubieboard上安装NodeJS,下载别人已经编译完成适用于Cubieboard的NodeJS二进制包,或者自己下载源码自行在Cubieboard上进行编译. 使用编译完成 ...
- 在(Raspberry Pi)树莓派上安装NodeJS
本文主讲如何在树莓派3B上安装node.js 环境描述1. 树莓派安装了`2016-11-25-raspbian-jessie-lite`(PS:在此版本的镜像中,默认禁用了ssh,在烧录好镜像之后, ...
- Building and running Node.js for Android
转自: http://www.goland.org/nodejsonandroid/ Building and running Node.js for Android October 14, 2014 ...
- 10+ 最佳的 Node.js 教程和实例
如果你正在找Node.js的学习资料及指南,那么请继续(阅读),我们的教程将会覆盖即时聊天应用.API服务编写.投票问卷应用.人物投票APP.社交授权. Node.js on Raspberry Pi ...
随机推荐
- How does Circus stack compare to a classical stack?
Frequently Asked Questions - Circus 0.15.0 documentation https://circus.readthedocs.io/en/latest/faq ...
- python基础(int,str,bool,list)
1数字int. 数字主要是用于计算用的,使用方法并不是很多,就记住一种就可以: bit_length() #bit_length() 当十进制用二进制表示时,最少使用的位数 v = 11 1 ...
- Linux数据库的导入导出
Linux数据库的导入导出 1.导入数据库 mysql -u username -p test < /home/data/test.sql 说明:username是数据库用户名,test为目标数 ...
- 利用PWM脉宽调制实现呼吸灯
1.设计目标 完成一个呼吸灯,从亮到灭的时间为2秒,从灭到亮的时间为2秒,以此不断往复. 2.设计步骤 2.1设计分析 利用PWM(脉冲宽度调制)实现led灯亮度的变化,只需要改变占空比就可以实现,具 ...
- shell脚本的使用该熟练起来了,你说呢?(篇三)
继续前一篇的文章: shell脚本的使用该熟练起来了,你说呢?(篇一) shell脚本的使用该熟练起来了,你说呢?(篇二) 文章里面测试的命令脚本文件,大家关注我公众号后,可以私信我领取文件. 作者: ...
- Codeforces Round #673 (Div. 2) D. Make Them Equal(数论/构造)
题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$ ...
- 2019牛客多校 Round3
Solved:3 Rank:105 治哥出题了 我感动哭了 A Graph Game (分块) 题意:1e5个点 2e5条边 s(x)表示与x点直接相邻的点集合 有两种操作 1种将按输入顺序的边第l条 ...
- 【51nod1674】区间的价值 V2(算法效率--位运算合并优化+链表实现)
题目链接: 51nod1674 题意:规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积.现在l有一个 N 个数的序列,问所有n*(n+1)/2个区间的贡献的和对1 ...
- python实现通过指定浏览器免费观看vip视频
程序是先通过一个解析视频的网站,然后我们提取其接口,然后实现观看vip视频的目的 所以说免费观看视频python程序很容易,但是下载视频就有些许麻烦了,下载视频请见我另一篇博客:python+fidd ...
- CodeForces - 1201B Zero Array
You are given an array a1,a2,-,ana1,a2,-,an. In one operation you can choose two elements aiai and a ...