How to read bytes from a Socket in Haskell

haskell, networking, sockets

Solution

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

Problem

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?

Original source