为什么Windows需要使用套接字? [英] Why does windows need withSocketsDo?

查看:459
本文介绍了为什么Windows需要使用套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在windows中,套接字需要初始化,如网络


在Windows操作系统上,网络子系统必须使用withSocketsDo进行初始化,然后才能进行任何联网操作用过的。例如

  main = withSocketsDo $ do {...} 

虽然这只在Windows平台上非常必要,但在其他平台上是无害的,因此为便于携带,始终可以使用它。


关于windows有什么特别之处?

解决方案

现有版本的网络库 withSocketsDo 用于初始化 Winsock库 a>,这只是Windows上的一项要求。在其他平台上,没有库需要初始化,所以 withSocketsDo 什么都不做。在这个网络库的未来版本中, code> withSocketsDo 会自动调用,因此只需要包含与旧版本的兼容性,请参阅这篇博文了解更改背后的细节。


In windows, sockets need to be initialized, as shown in 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.

What's special about windows?

解决方案

In existing versions of the network library, withSocketsDo is used to initialize the Winsock library, which is only a requirement on Windows. On other platforms no library needs initializing, so withSocketsDo does nothing.

In future versions of the network library, withSocketsDo is called automatically, so only needs to be included for compatibility with older versions, see this blog post for the details behind the changes.

这篇关于为什么Windows需要使用套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆