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

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Jun 26 22:37:07 EDT 2007


chad.scherrer:
> Ok, cool. FWIW, the current documentation for Network says:
> 
> "For really fast I/O, it might be worth looking at the hGetBuf and
> hPutBuf family of functions in System.IO."
> 
> But this looked pretty low-level to me, and I figured it might be outdated.
> 
> I also know Bulat Ziganshin had put together a nice-looking Streams
> library (http://unix.freshmeat.net/projects/streams/) based on John
> Goerzen's previous HVIO work, but I wasn't sure if the ByteString
> stuff matches the speed and encapsulates all of the functionality of
> that anyway. Or can/should they be used together somehow?

Should be similar in speed, and most high-perf stuff seems to use
ByteStrings now. ByteStrings also have some nice high level
optimisations not available to lower level libraries.

> 
> 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