☮️正向连接

架默认作为服务端 启动监听的端口即为SocketIO服务端口

这里以Python Client为例 无论任何语言 只需关心这个2个事件OnWeChatMsgs,OnWeChatEvents即可 数据都是JSON

#注意版本!
#Flask-SocketIO==4.3.2
#python-engineio==3.14.2 
#python-socketio==4.6.1



''' Demo'''
import socketio

# standard Python
sio = socketio.Client(logger=True, engineio_logger=True)

# SocketIO Client
#sio = socketio.AsyncClient(logger=True, engineio_logger=True)

# -----------------------------------------------------
# Socketio
# -----------------------------------------------------


@sio.event
def connect():
    print('connected to server')


@sio.on('OnWeChatMsgs')
def OnWeChatMsgs(message):
    ''' 监听Wx消息'''
    print(message)


@sio.on('OnWeChatEvents')
def OnWeChatEvents(message):
    ''' 监听Wx事件 '''
    print(message)

# -----------------------------------------------------


def main():
    sio.connect('http://127.0.0.1:8089', transports=['websocket'])

    sio.wait()
    # Cleanup
    sio.disconnect()


if __name__ == '__main__':
    main()

Last updated