[Haskell-cafe] non-blocking recv from UDP socket
Vo Minh Thu
noteed at gmail.com
Thu Aug 26 13:04:16 EDT 2010
2010/8/26 Brandon S Allbery KF8NH <allbery at ece.cmu.edu>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> On 8/26/10 05:13 , Vo Minh Thu wrote:
>> Is is possible to get Network.Socket.ByteString.recv to be
>> non-blocking (i.e. return directly even if no data is available) ?
> "What are you really trying to do?"
> The Haskelly solution to this is to use threads; let the thread reading the
> socket block and the main thread synchronize with it somehow. (Haskell
> threads are very inexpensive; don't be afraid of them.)
Well, I have written the FFI and it works fine.
What I'm doing is the networking part of a game loop following some
nice ressource. I'll wait a bit to have more experience with the
code before changing how it is designed (e.g. using light threads).
Fast paced 3D action games (and physics) networking seems quite
At first sight for instance, it seems easier to have an 'update'
function for the networking code to detect timeout than to have it
implemented on top of a waiting thread. (Such an update function is
quite pervasive in a (imperative) game loop). Also the same socket is
used both to read and write, so this would need additional
But thanks for the suggestion, it might be a good one later on.
More information about the Haskell-Cafe