简体   繁体   中英

Python: Send data to socket.io

Now I have create a node.js server, and linked it with php page and it works fine. So right now is it possible for Python to send socket.io signal (with data of course) to socket.io server and Python is game program, where it will transmit current game stats, and the Python will not receive any data from Socket.io server.

So the connection that will establish will kinda like this: Python (game) -> Socket.io <-> Client

Message/Signal Python will send to server (JSON): {name: 'stats', user: 'username': .... }

If you want to use Python to talk with a socket.io server, you can use socketIO-client .

from socketIO_client import SocketIO

def on_bbb_response(*args):
    print 'on_bbb_response', args

with SocketIO('localhost', 8000) as socketIO:
    socketIO.emit('bbb', {'xxx': 'yyy'}, on_bbb_response)
    socketIO.wait_for_callbacks(seconds=1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM