Socket.IO

好记性不如烂笔头系列:npm 笔记

て烟熏妆下的殇ゞ 提交于 2020-08-14 16:25:59
安装npm npm 是 nodejs 的一部分,因此需要安装 nodejs ,从 官网下载 对应的版本,我使用 Linux64bit 的版本,下载后得到一个 xxx.tar.xz 的文件。解压 tar.xz 文件:先用 xz -d xxx.tar.xz 将 xxx.tar.xz 解压成 xxx.tar 然后,再用 tar xvf xxx.tar 来解包。得到一个类似 node-12.12.34 的包,重命名为 node ,放到 /usr/local/ 下,修改 .bashrc 的 $PATH 变量,加入以下内容: #nodeJs export NODEBIN=/usr/local/node/bin export PATH=$NODEBIN:$PATH 执行 source ~/.bashrc && npm -v 输出 npm 版本即安装成功 显示npm配置 npm config ls -l 其中 userconfig = "/Users/falcon/.npmrc" 是当前用户配置项,使用下面的命令修改相关设置并写入这个文件。 prefix 是全局安装时的位置,如 运行 npm config get prefix 显示 /usr/local ,那么packages 会安装到 /usr/local/lib/node_modules 下 获取当前配置的registry npm

nginx为workerman、socketio提供ssl

天涯浪子 提交于 2020-08-11 14:31:08
nginx location /wss { proxy_pass http://127.0.0.1:3322; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Real-IP $remote_addr; } location /socket.io { proxy_pass http://127.0.0.1:3310; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Real-IP $remote_addr; } apache # Proxy Config ProxyRequests Off ProxyPass /wss ws://127.0.0.1:3322 ProxyPassReverse /wss ws://127.0.0.1:3322 ProxyPass /socket.io http://127.0.0.1:3310 ProxyPassReverse /socket.io http:/

给你一套完整的学习web前端线路图

回眸只為那壹抹淺笑 提交于 2020-08-11 11:26:17
随着网络时代的壮大,前端也成为了很多企业不可缺少的一部分。前端的人才也日益扩大,前端的技术也在日益更新,如何成为一名合格的前端工程师,应该怎么学习才有效果呢? 首先、前端工程师学习分为几种:自学、系统培训班、线上教学等。 其次、学习前端几种方法的利弊: 1.自学,自学相对于很多学生来说是特别难的,自学要有足够的韧劲和坚持,自学过程中会遇到很多难点,需要自己去逐步查资料等解决,而且自学最后要走向工作时,没有一个实战经验,对以后参加工作来说是一个很大的问题。 2.系统培训班,最快也是最有效的方法就是去培训班学习了,爱创课堂培训班教学思路都是比较清晰的,给学生的知识传递也非常明确,而且爱创培训班有实战教学,在参加工作的时候帮助很大。 3.线上教学,像今年线上教学是非常重要的,很多学生迫于无奈只能线上学习。线上教学也是一个不错的方法,线上老师讲解也特别清楚,与培训班线下教学的差别就是不能面对面,但知识点都是一样的。爱创也有线上教学,老师讲解特别清楚。 最后、哪家培训班教学好? 爱创课堂是由前百度前端架构师,张容铭老师亲自带队授课全程面授、爱创是崇尚实战化教学,通过实战经验让更多前端学员思维变通,而不是一贯的学习死知识,不懂得变换,爱创课堂目前开设小班教学,一个班20-30人左右,老师针对全班每位学生,手把手教学,确保每位学员都能学会在爱创培训的所有知识。并且爱创对学员是非常负责任的

pass socket.io to router module in node js

ε祈祈猫儿з 提交于 2020-08-11 01:39:31
问题 snippet below is clear // app.js const express = require('express'); const app = express(); const http = require('http').createServer(app); const io = require('socket.io')(http); const studentRouter = require('./routes/student') app.use('/students', studentRouter) but here app.use('/students', studentRoute) I want to pass io to studentRouter , How can I do that ? and this is my studentRouter : // student route const express = require('express'); const router = express.Router(); router.route('

Error when connecting to a secure Socket.io connection using self signed certificate from a browser app

你离开我真会死。 提交于 2020-08-10 20:20:27
问题 Socket.io client API documentation suggests that the client should pass the self signed certificate in the connection request to the server: // client-side const socket = io({ca: fs.readFileSync('server-cert.pem'),rejectUnauthorized: false}); This works great in a node environment. How to make this work in a BROWSER javascript app? I am facing two issues: How can I include the certificate file in the browser app? readfileSync cannot find the file If I only include rejectUnauthorized: false in

Socket double emits problem in express route (event handler stacking)

拟墨画扇 提交于 2020-08-10 19:37:27
问题 I have problem with stacking socket event handler when hitting express route. I need to reconnect in route then sending emit to specific room. At first I connect (socket.io) at page X, then connection is lost cause I move to page Y (with use of router.post) and then in router when I reconnect I add new global socket.io handler for the connection event... and cause of that emits are send multiple times. Ideally, I should use some kind of session to know that user disconnect/connect and be able

Socket double emits problem in express route (event handler stacking)

醉酒当歌 提交于 2020-08-10 19:36:35
问题 I have problem with stacking socket event handler when hitting express route. I need to reconnect in route then sending emit to specific room. At first I connect (socket.io) at page X, then connection is lost cause I move to page Y (with use of router.post) and then in router when I reconnect I add new global socket.io handler for the connection event... and cause of that emits are send multiple times. Ideally, I should use some kind of session to know that user disconnect/connect and be able

How do I let socket.io server re-emit message to a particular socket when that socket re-connect?

守給你的承諾、 提交于 2020-08-10 19:22:06
问题 My server codes use io.to(socketId).emit('xxx'); to a message to a particular socket, refer to https://socket.io/docs/emit-cheatsheet/ But when the connection is bad and the client disconnects and connects again, socketId changes and io.to(socketId).emit('xxx'); then fails. So how do I implement a re-emit method to handle the reconnection ? My question is kind of opposite to this one, socket.io stop re-emitting event after x seconds/first failed attempt to get a response, from it I learn that

Socket.io with Apache Proxy (Connection refused)

半世苍凉 提交于 2020-08-10 19:14:05
问题 I have been implementing Socket.io in a node.js server and SSL. I was first facing an SSL handshake error which I have resolved successfully. I do not expose the node.js port directly to the internet and all socket connections are proxied through a public Apache HTTPS server. The problem is that when trying to connect to the socket the browser will return the following error: WebSocket connection to 'wss://domain.com:4923/socket.io/?EIO=3&transport=websocket' failed: Connection closed before

Socket.io is not connecting on Heroku

家住魔仙堡 提交于 2020-08-10 19:09:07
问题 I am using Socket.io in my NodeJS backend. However, the sockets do not work. For example, one should receive a link and then send them to all other rooms under the same code, but the code is not executing. In my heroku logs I receive no errors but when I inspect element the page I get polling-xhr.js:268 GET https://localhost:5000/socket.io/?EIO=3&transport=polling&t=NDADDNH net::ERR_CONNECTION_REFUSED and Failed to load resource: net::ERR_CONNECTION_REFUSED I have looked into similar problems