我正在尝试使用 socket.io 将值从我的树莓派(在 python 2.7.9 中)发送到我的 nodeJS 服务器。
我的目标是通过 websocket 连接从我的 pi 连续发送许多值到我的节点服务器(本地),该服务器应该获取这些值并将其显示在 index.html 上(对于其他客户端,例如仅树莓派发送的网络聊天)值)
我尝试了一切,但无法握手和发送数据。当我打开“http://IP_ADDRESS:8080 http://IP_ADDRESS:8080“在我的浏览器中,我看到了一个连接,但没有看到我的 python 代码。
请我需要一些帮助......
服务器.js
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, conf = require('./config.json');
// Webserver
server.listen(conf.port);
app.configure(function(){
app.use(express.static(__dirname + '/public'));
});
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/index.html');
});
// Websocket
io.sockets.on('connection', function (socket) {
//Here I want get the data
io.sockets.on('rasp_param', function (data){
console.log(data);
});
});
});
// Server Details
console.log('Ther server runs on http://127.0.0.1:' + conf.port + '/');
我的蟒蛇网络套接字-我只想发送值的代码
#!/usr/bin/env python
#
from websocket import create_connection
ws = create_connection("ws://IP_ADDRESS:8080/")
ws.send("Some value")
ws.close();
Socket.io 通信不是普通的 websocket。您可能需要在 python 上实现 socket.io 客户端,以确保您发送的消息与 socket.io 协议兼容。就像是socketIO-客户端 https://pypi.python.org/pypi/socketIO-client, maybe.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)