HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Modulenetwork-run-0.6.0Haskell2010

Network.Run.UDP

Simple functions to run UDP clients and servers.

  • 1 type
  • 9 values
valuerunUDPServerFork
  1. :: [HostName]
  2. -> ServiceName
  3. -> Socket -> ByteString -> IO ()
  4. -> IO ()
#

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.