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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With