![](/img/trans.png)
[英]python SocketIO-client and nodejs socket.io server namespace mismatch
[英]Python Client to nodeJS Server with Socket.IO
我正在嘗試從我的raspberry pi(在python 2.7.9中)發送值到socket.io的nodeJS服務器。
我的目標是通過websocket連接從我的pi連續發送許多值到我的節點服務器(本地),它應該獲取值並在index.html上顯示(對於其他客戶端,例如只有覆盆子發送的Web-Chat)值)
我嘗試了一切,但我無法握手並發送數據。 當我在瀏覽器中打開“ http:// IP_ADDRESS:8080 ”時,我看到了一個連接,但沒有看到我的python代碼。
我需要一些幫助....
server.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 + '/');
我的python websocket -code,我只想發送值
#!/usr/bin/env python
#
from websocket import create_connection
ws = create_connection("ws://IP_ADDRESS:8080/")
ws.send("Some value")
ws.close();
Socket.io通信不是普通的websockets。 您可能需要在python上實現socket.io客戶端,以確保您發送的消息與socket.io協議兼容。 也許像socketIO-client這樣的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.