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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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