T
T
tupoi2016-10-02 14:44:11
Python
tupoi, 2016-10-02 14:44:11

Why is asynchronous http server not accepting connections?

Good day. Just started to deal with asynchronous programming in Python 3.
It is necessary to implement a client-server application:
1. The client gets to the server, receives from it in response the connection settings (port, number of files, format) in json format via http
2. By sending these settings, the server creates a socket on the port that it sent to the client and waits for it to connect and accept files in the required quantity and formats, while continuing to register other connected to free ports.

import tornado.ioloop
import tornado.web
import time

def looper():
    time.sleep(10)

class MainHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        self.write('hello')
        self.finish()
        looper()

def app():
    return tornado.web.Application([
        (r'/', MainHandler),
    ])

if __name__ == "__main__":
    app = app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

this is the server code, this is not a working option, I just decided to simplify the task to check when I connect for the first time, then everything is fine, when I reconnect, nothing comes out and I wait 10 seconds, is it possible to somehow make it send json, call the necessary function from an instance of the class and passed the same parameters to it, and then again began to listen? at the same time, files were received via the socket
. Examples or answers will work both on Tornado and on aiohttp
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-10-02
@AMar4enko

When working with an event loop, forget about any blocking I/O operations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question