from socketIO_client import SocketIO, BaseNamespace
class Namespace(BaseNamespace):
def on_aaa_response(self, *args):
print('on_aaa_response', args)
self.emit('bbb')
socketIO = SocketIO('localhost', 3000, Namespace)
def on_connect():
print('Connected')
socketIO.on('connect', on_connect)
socketIO.on('chatmessage', on_message)
socketIO.wait(seconds=1000)
我如何与node.js服务器连接,以便我可以在python客户端和node.js客户端之间发送命令? 这是我的服务器代码 请建议更改。 或者是否有任何人有类似的项目链接?
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){ console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
io.on('connection', function(socket){
socket.on('chatmessage', function(msg){
io.emit('chatmessage', msg);
});
});
io.on('connection', function(socket){
socket.on('chatmessage', function(msg){
console.log('message: ' + msg);
});
});
io.emit('some event', { for: 'everyone' });
http.listen(3000, function(){
console.log('listening on *:3000');
});