在 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/