Y
Y
Yourmind2019-07-31 21:34:55
Python
Yourmind, 2019-07-31 21:34:55

Asynchronous python server?

I am writing a server for a game. But I can't figure out how to make it multi-threaded.
for example, if you only needed to work with one client, you could simply write:

import socket
sock = socket.socket()
sock.bind(('', 9090))
sock.listen(1)
conn, addr = sock.accept()
while True:
    data = conn.recv(1024)
     if not data:
        break
conn.close()


I could receive messages from several clients in this way. But in this case the server would be synchronous. To achieve asynchrony, each client must provide its own stream so that requests from other users do not interfere with listening to this one in time. How to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Iontzev, 2019-08-04
@iontzev

Use aiohttp, development of one of the authors of asyncio Andrey Svetlov
QuickStart

R
Roman Kitaev, 2019-07-31
@deliro

RTFM https://docs.python.org/3/library/socketserver.htm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question