HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulenetwork-run-0.6.0Haskell2010

Network.Run.UDP

Simple functions to run UDP clients and servers.

Synopsis

Running a UDP server with a connected socket in each Haskell thread. The first request is given to the server. Suppose that the server is serving on addrS:portS and a client connects to the service from addrC:portC. A connected socket is created by binding to *:portS and connecting to addrC:portC, resulting in (UDP,addrS:portS,addrC:portC) where addrS is given magically. This approach is fragile due to NAT rebidings.

datadata ServerSettings

Settings for servers.

Fields which do not apply to a given server (for instance the graceful close timeout for a UDP server) are ignored.

Constructors

Open socket for server use, and set the provided options before binding.

In addition to the given options, the socket is configured to

  • allow reuse of local addresses (SO_REUSEADDR)

  • accept IPv6 only, rejecting IPv4-mapped addresses, if the address family is AF_INET6 (IPV6_V6ONLY)

  • automatically be closed during a successful execve (FD_CLOEXEC)

  • bind to the address specified

Because IPV6_V6ONLY is in effect, a socket bound to :: does not accept IPv4 connections. To serve both families, open one socket per address and run a server on each of them with runTCPServerWithSocket.

The given options are set after the ones above, so (IPv6Only, 0) can be passed to ask for a dual stack socket. Note that OpenBSD always makes IPv6 sockets IPv6 only; the option is not set there and cannot be cleared.