[Haskell-cafe] Simple network client

Adam Langley agl at imperialviolet.org
Wed Jan 30 12:25:58 EST 2008


On Jan 30, 2008 4:32 AM, Jules Bean <jules at jellybean.co.uk> wrote:
> The third, but more sophisticated answer is to use non-blocking IO, read
>   'only what is available', decide if it's enough to process, if not
> store it in some local buffer until next time. This is much more work
> and easy to implement bugs in, but you need it for true streaming
> protocols.  In that case hGetBufNonBlocking is your friend.

If using bytestrings from the network, the network-bytestring package
is what you need.

If you're parsing small lumps from the network, Data.Binary's failures
will probably make life harder than it should be for you since they
can only be caught in IO. See
http://www.haskell.org/haskellwiki/DealingWithBinaryData about a
strict Get which might work for you.

Also, if you want the above approach (read a bit, see if it's enough),
see IncrementalGet in the binary-strict package which is a Get with a
continuation monad that stops when it runs out of bytes and returns a
continuation that you can give more data to in the future.


AGL

-- 
Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       650-283-9641


More information about the Haskell-Cafe mailing list