network-run-0.4.3: Simple network runner library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.Run.TCP

Contents

Description

Simple functions to run TCP clients and servers.

Synopsis

Server

runTCPServer :: Maybe HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP server with an accepted socket and its peer name.

runTCPServerWithSocket Source #

Arguments

:: Socket 
-> (Socket -> IO a)

Called for each incoming connection, in a new thread

-> IO a 

Running a TCP client with a connected socket for a given listen socket.

openTCPServerSocket :: AddrInfo -> IO Socket Source #

Open TCP socket for server use

This is the same as:

openTCPServerSocketWithOptions []

openTCPServerSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket Source #

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

This is equivalent to

openTCPServerSocketWithOpts . map (second SockOptValue)

openTCPServerSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket Source #

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)
  • automatically be closed during a successful execve (FD_CLOEXEC)
  • bind to the address specified
  • listen with queue length with 1024

Client

runTCPClient :: HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP client with a connected socket.

This is the same as:

runTCPClientWithSettings defaultSettings

data Settings Source #

Settings for client.

defaultSettings :: Settings Source #

Default settings.

runTCPClientWithSettings :: Settings -> HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP client with a connected socket.

openClientSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket Source #

Open a client socket with the given options

The options are set before connect. This is equivalent to

openClientSocketWithOpts . map (second SockOptValue)

openClientSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket Source #

Open a client socket with the given options

This must be used rather than openClientSocketWithOptions for options such as Linger which require a composite value (StructLinger).

The options are set before connect.