Formatting messages to send to socket.io node.js server from python client

前端 未结 2 2039
情歌与酒
情歌与酒 2020-12-24 13:29

I\'m trying to get a Python client talking to a Node.js server using Socket.io 0.7, by sending a custom event to the server.

Based on the Socket.io reference I have

相关标签:
2条回答
  • 2020-12-24 14:16

    Resolved. I needed to use double quotes. Single quotes are not valid JSON. Woops.

    ws.send("5:1::{'name':'newimg', 'args':'bla'}")
    

    Becomes:

    ws.send('5:1::{"name":"newimg", "args":"bla"}')
    
    0 讨论(0)
  • 2020-12-24 14:23

    I wrapped rod's research into a barebones socket.io client library.

    pip install -U socketIO-client
    python
        from socketIO_client import SocketIO
        with SocketIO('localhost', 8000) as socketIO:
            socketIO.emit('aaa')
            socketIO.wait(seconds=1)
    
    0 讨论(0)
提交回复
热议问题