sockets - 为什么windows需要withSocketsDo?

标签 sockets haskell

在 windows 中,socket 需要初始化,如 Networks 所示。

On Windows operating systems, the networking subsystem has to be initialised using withSocketsDo before any networking operations can be used. eg.

  main = withSocketsDo $ do {...}

Although this is only strictly necessary on Windows platforms, it is harmless on other platforms, so for portability it is good practice to use it all the time.


window 有什么特别之处?

最佳答案

在现有版本的网络库中,withSocketsDo 用于初始化 Winsock library ,这只是 Windows 上的要求。在其他平台上,没有库需要初始化,所以 withSocketsDo 什么都不做。

在网络库的 future 版本中,会自动调用 withSocketsDo,因此只需要包含与旧版本的兼容性,更改背后的详细信息请参见 this blog post

关于sockets - 为什么windows需要withSocketsDo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22430686/

相关文章:

java - Phantasia4(Java 客户端和 C 服务器)套接字超时

android服务 - 打开套接字抛出空异常

python - 在没有root的情况下在Python中实现UDP traceroute

haskell - 为什么 `putStrLn getLine` 不起作用?

haskell - 泛化类参数

haskell - Data.Map 中的函数 -> 也许作为类实例。困惑如何实现

haskell - 用户应该使用/避免哪些 Haskell (GHC) 扩展?

haskell - 如何为 Typeable 添加实例声明

python - 尝试在 Windows 上的 Python 3 中使用套接字时出现 Winsock 错误 10014

c - 一个信号在阻塞模式下中断发送方法