如何在 Haskell 中从 Socket 读取字节
我正在尝试从 Haskell 中的套接字读取多个字节。基本上我想做一些与此等效的事情:
client_socket.recv(255) #(Python)
最好的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有Network.Socket,它有recvFrom 和recvBufFrom。第一个假设您想要一个字符串,如果您想要二进制数据,您当然不需要它。第二个使用指针,您可能不想处理它。还有socketToHandle,非常有用。
不过,我的推荐是network-bytestring库。它支持惰性和严格字节串。 http://hackage.haskell.org/package/network-bytestring
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
对于此类初学者问题,查看 RWH
作为一般经验法则,您应该始终查看 Hackage 中的库和文档。要搜索函数,Hayoo 和 Hoogle 是你的朋友。
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.