Re: UDP socket server issues Python

In the end it's wrong.  For now it may not be.

The first most obvious problem is that that's catching too many errors.  I don't know offhand what all sockets can throw but it's certainly more than "try again please".

But the second thing is that that only really works with UDP sockets, and it doesn't account for cases when writes might block or be unable to be handled.  Once you're doing both reading and writing of multiple clients in parallel, you can't just spin round and round waiting to be able to send data out, because while you're trying to send data out someone might be trying to send data in, and since this is UDP if you're not reading fast enough data will just get dropped.  you're going to have to eventually handle the fact that UDP is unreliable anyway, but trying to handle everything by just spamming the syscalls without using something more proper will just compound those problems unless you're very careful.

If select scares you and if asyncio scares you, use two threadsafe queues (see the queue module), leave the socket in blocking mode, and use two threads--one reading and writing to a queue called read_queue, one writing messages off a write_queue.  Then your main loop becomes:

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector

Reply via email to