views:

220

answers:

2

I'm trying to read a number of Bytes from a socket in Haskell. Bascially I want to do something equivalent to this:

client_socket.recv(255) #(Python)

What's the best way of doing it?

+11  A: 

There's Network.Socket, which has recvFrom and recvBufFrom. The first one assumes you want a String, which you certainly don't want if you want binary data. The second one uses a pointer, which you probably don't want to deal with. There's also socketToHandle, which is very useful.

However, my recommendation is the network-bytestring library. It supports both lazy and strict bytestrings. http://hackage.haskell.org/package/network-bytestring

Dietrich Epp
Thanks for the help mate
MattyW
+2  A: 

For this kind of beginner questions, it's not a bad idea to check out RWH first.

And as a general rule of thumb, you should always look at Hackage for libraries and documentation. To search for a function, Hayoo and Hoogle are your friends.

Wei Hu
Thanks Wei Hu. I've got a copy of RWH - but unfortunately I'm in the middle of moving house and it's ended up in a box. But I'd forgotten about the online one. Thanks for the reminder!
MattyW