Python Forum
Impementing a client that connects to the server - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Impementing a client that connects to the server (/thread-39486.html)



Impementing a client that connects to the server - input - Feb-25-2023

I have a cllient and webserver running but when connecting I receive a 404:not found error.
import socketio
sio = socketio.Client()
@sio.event
def connect():
    print (' connection established')
@sio.event
def disconnect():
    print(' disconnected from server')
sio.connect ('http://localhost:8080')
sio.emit('message', {'data':'my_data'})
sio.wait()
import socketio
from aiohttp import web
socket_io = socketio.AsyncServer()
app = web.Application()
socket_io.attach(app)

async def index(request):
    return web.Response(text='Hello world from socketio',content_type='text/html')
from aiohttp import web

@socket_io.on('message')
def print_message(socket_id, data):
    print("Socket ID:' , socket_id")
    print("Data : ", data)
    app.router.add_get('/', index)

if __name__=='__main__':
    web.run_app(app)