# 反向连接

{% hint style="warning" %}
通过配置配置文件CoreConf.conf的

SocketIOUrl = "ws://127.0.0.1:8081/socket.io/?EIO=3\&transport=websocket"

字段,让框架作为客户端链接SocetIO v3服务端

下面2段代码都可用 注意版本即可
{% endhint %}

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

"""
import eventlet
import socketio

sio = socketio.Server(logger=True, engineio_logger=True)
app = socketio.WSGIApp(sio, static_files={
    '/': {'content_type': 'text/html', 'filename': 'index.html'}
})


@sio.event
def connect(sid, environ):
    print('connect ', sid)


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


@sio.on('OnWeChatEvents', namespace='/')
def OnWeChatEvents(message):
    ''' 监Wx事件 '''
    print(message)


@sio.event
def disconnect(sid):
    print('disconnect ', sid)


if __name__ == '__main__':
    eventlet.wsgi.server(eventlet.listen(('', 8081)), app)
"""

from flask import Flask
from flask_socketio import SocketIO, emit

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, logger=True, async_mode=None, engineio_logger=True)


@app.route('/')
def index():
    return 'ok'

@socketio.on('OnWeChatEvents')
def OnWeChatEvents(message):
    ''' 监听相关事件'''
    print(message)

@socketio.on('OnWeChatMsgs')
def OnWeChatMsgs(*message):
    print('OnWeChatMsgs message')
    print(message)
    print('----------')
   




if __name__ == '__main__':
    socketio.run(app, port=8081)
 
```
