我查看 GitHUB - Arduino Serialport Socket.io 中的代码一切都很好。它的工作和它应该的一样好。该项目包含(来自 package.json):
"dependencies": {
"serialport": "*",
"socket.io": "0.9.6"},
"engines": { "node": "0.6" }
但是当我复制 app.js 和/web/index.html 时,我想通过执行以下操作来安装新包
npm install serialport --save
npm install socket.io --save
npm install node --save
我进入package.json:
"dependencies": {
"serialport": "~2.0.2",
"socket.io": "~1.3.7",
"node": "0.0.0",}
如您所见,版本不一样。并且该程序无法运行。似乎 socket.io 没有启动。串口向终端发送数据,网页正常工作,但没有从套接字接收数据。 终端(旧 socket - 它可以工作):
user@user-K52Jc:~/sio$ node app.js
Server started on localhost:3000
info - socket.io started
Port opened... Press reset on the Arduino.
serial port: A474B
终端(新套接字 - 它不起作用):
user@user-K52Jc:~/ArdWEB_POT$ node app.js
Server started on localhost:3000
Port opened... Press reset on the Arduino.
serial port: A474B
谁能帮我解决这个问题吗?帮助
顺便说一句。在 Chrome 中 Ctrl+Shift+C 打开控制台,它给出日志错误:GET http://localhost/socket.io/?EIO=3&transport=polling&t=1446114714737-4 net::ERR_CONNECTION_REFUSED
也许会有帮助。
最佳答案
很抱歉出现这个问题。我下载了很多应用程序,现在我知道答案了。 问题出在index.html 中的那一行
var socket = io.connect("/", {
它必须是:
var socket = io.connect("http://localhost:3000/", {
关于javascript - Socket.io - 旧版本的 app.js 到新版本的 socket.io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33411563/