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, unlike other platforms, requires processes to kickstart their network connectivity by manually initializing WinSock.dll. Meanwhile, Haskell, unlike other languages, by design does not have global mutable state. Thus, the WinSock initialization can't be hidden inside the load of a library or creation of some singleton object, and instead needs to be registered manually by an explicit call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With