[Haskell-cafe] Preferred way to get data from a socket

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Jun 26 21:54:23 EDT 2007


chad.scherrer:
> I've never used sockets before, but I need to now, and I need to be
> able to get a lot of data quickly. I was thinking about doing
> something like this (below), but I'm wondering if there's a way that
> would be faster. Is the obvious way of doing this "the right way"? I'm
> happy to install outside libraries if that would help, as long as they
> work on Linux and MS. Thanks!
> 
> -Chad
> 
> ----------------------8<-------------------------------
> 
> import Network
> import qualified Data.ByteString.Lazy as B
> 
> hostName = "myComputer"
> portID = PortNumber 54321
> 
> theData :: IO B.ByteString
> theData = connectTo hostName portID >>= B.hGetContents
> _______________________________________________

Looks like the obvious, right way to me.

-- Don


More information about the Haskell-Cafe mailing list