Running multiple sockets using asyncio in python

后端 未结 1 1061
既然无缘
既然无缘 2021-01-27 03:18

Setup: Python 3.7.4

I am trying to create 6 sockets using asyncio listening on different ports. I tried to implement it like this.

Code:

import asyn         


        
相关标签:
1条回答
  • 2021-01-27 03:58

    Rewrite your enable_sockets function like this:

    def enable_sockets():
        try:
            host = '127.0.0.1'
            port = 60000
            sockets_number = 6
            loop = asyncio.get_event_loop()
            for i in range(sockets_number):
                loop.create_task(start_servers(host,port+i))
            loop.run_forever()
        except Exception as exc:
            print(exc)
    
    0 讨论(0)
提交回复
热议问题