import socket,time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
        data, addr = s.recvfrom(1024)
        if addr not in clients:

        if not lines:
            for client in clients:
                s.sendto(lines, client)

I have paint application, in which the server sends the co-ordinates to a set of clients. I use the above code for sending, launching on a separate thread. This sends data to each client sequentially. This will cause a delay to the clients at the end of the list. Launching a separate thread for each client has scalability issues. Is there is scalabe way to write the above code maybe using async.io?

  • \$\begingroup\$ Why the downvote? \$\endgroup\$ – Abhishek Bhatia Mar 17 '16 at 19:29
  • \$\begingroup\$ I rolled back your changes. Editing the question after it's been answered is against the Code Review chapter, because it invalidates the review. See the codereview.stackexchange.com/help/someone-answers for what you should and shouldn't do. \$\endgroup\$ – vnp Mar 17 '16 at 21:33

You cannot use recvfrom with a TCP socket (SOCK_STREAM). You don't see the error, because of your wrong exception handling. Never ignore all exceptions! Don't write your own server, use the appropriate interface from asyncio.

| improve this answer | |
  • \$\begingroup\$ It should be recvinstead? Which interface are talking about, please tell. \$\endgroup\$ – Abhishek Bhatia Mar 17 '16 at 18:44
  • \$\begingroup\$ What do you want? \$\endgroup\$ – Daniel Mar 17 '16 at 18:58
  • \$\begingroup\$ I want it to send data to all clients asynchronously. \$\endgroup\$ – Abhishek Bhatia Mar 17 '16 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.