title: How to send message on python-socketio
body: <p>The API documentation (<a href="https://python-socketio.readthedocs.io/en/latest/intro.html" rel="nofollow noreferrer">https://python-socketio.readthedocs.io/en/latest/intro.html</a>) provides examples of the server and client. But if you run them, you will not start messaging. And I'm not sure how to set it up.</p>
  
  <p>How do I set up messaging so I can output their body through the <code>print</code> function?</p>
  
  <p><strong>client.py</strong></p>
  
  <pre><code>import socketio
  
  sio = socketio.Client()
  
  
  @sio.event
  def connect():
      print('connection established')
  
  
  @sio.event
  def my_message(data):
      print('message received with ', data)
      sio.emit('my response', {'response': 'my response'})
  
  
  @sio.event
  def disconnect():
      print('disconnected from server')
  
  
  sio.connect('http://localhost:5000')
  sio.wait()
  </code></pre>
  
  <p><strong>server.py</strong></p>
  
  <pre><code>import eventlet
  import socketio
  
  
  sio = socketio.Server()
  app = socketio.WSGIApp(sio, static_files={
      '/': {'content_type': 'text/html', 'filename': 'index.html'}
  })
  
  
  @sio.event
  def connect(sid, environ):
      print('connect ', sid)
      my_message(sid, {'Test': 'Message'})
  
  
  @sio.event
  def my_message(sid, data):
      sio.send(data)
      print('Send message ', data)
  
  
  @sio.event
  def disconnect(sid):
      print('disconnect ', sid)
  
  
  if __name__ == '__main__':
      eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
  </code></pre>
  
  <p>Trace <em>client.py</em></p>
  
  <pre><code>venv) user@debian:~/work/self_prj/socket_io$ python3 client.py
  connection established
  </code></pre>
  
  <p>Trace <em>server.py</em></p>
  
  <pre><code>(13043) wsgi starting up on http://0.0.0.0:5000
  (13043) accepted ('127.0.0.1', 50352)
  127.0.0.1 - - [11/Sep/2019 15:24:08] "GET /socket.io/?transport=polling&amp;EIO=3&amp;t=1568204648.5529237 HTTP/1.1" 200 385 0.000619
  connect  cff05ec678794128a6541f33bf3ef6dd
  Send message  {'Test': 'Message'}
  (13043) accepted ('127.0.0.1', 50356)
  127.0.0.1 - - [11/Sep/2019 15:24:08] "POST /socket.io/?transport=polling&amp;EIO=3&amp;sid=cff05ec678794128a6541f33bf3ef6dd HTTP/1.1" 200 167 0.000148
  127.0.0.1 - - [11/Sep/2019 15:24:08] "GET /socket.io/?transport=polling&amp;EIO=3&amp;sid=cff05ec678794128a6541f33bf3ef6dd&amp;t=1568204648.5590577 HTTP/1.1" 200 183 0.002194
  127.0.0.1 - - [11/Sep/2019 15:24:33] "POST /socket.io/?transport=polling&amp;EIO=3&amp;sid=cff05ec678794128a6541f33bf3ef6dd HTTP/1.1" 200 167 0.000372
  127.0.0.1 - - [11/Sep/2019 15:24:33] "GET /socket.io/?transport=polling&amp;EIO=3&amp;sid=cff05ec678794128a6541f33bf3ef6dd&amp;t=1568204648.5659044 HTTP/1.1" 200 183 24.994966
  127.0.0.1 - - [11/Sep/2019 15:24:58] "POST /socket.io/?transport=polling&amp;EIO=3&amp;sid=cff05ec678794128a6541f33bf3ef6dd HTTP/1.1" 200 167 0.000355
  </code></pre>