[Haskell-cafe] Preferred way to get data from a socket
Chad Scherrer
chad.scherrer at gmail.com
Tue Jun 26 22:32:59 EDT 2007
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?
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