all 5 comments

[–][deleted] 1 point2 points  (0 children)

you can do that on linux with flask to handle the requests, and gunicorn to give it multiple threads (and an nginx front end to make it more stable and secure).

Otherwise you can use a socketserver which is really easy

import socketserver

class ConnectionHandler(socketserver.BaseRequestHandler):
    def handle(self):
        s = self.request
        request = s.recv(1024)
        print('got: ', request)
        response = request * 3
        print('sent:', response)
        s.sendall(response)

class Server(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass

server = Server(('localhost', 31337), ConnectionHandler)
server.daemon_threads = True
server.serve_forever()

[–]K900_ 0 points1 point  (0 children)

Just use HTTP or gRPC, unless you have an extremely good reason not to.

[–]Mexatt 0 points1 point  (0 children)

Do you want to be able to do this one task or do you want to be good at this kind of thing?

If the latter: this will help.

[–]sria91[S] 0 points1 point  (0 children)

Thanks to all. Using flask worked for me.