Module Network.NamedSocket

Library to support network programming with sockets that are addressed by symbolic names. In contrast to raw sockets (see library Socket), this library uses the Curry Port Name Server to provide sockets that are addressed by symbolic names rather than numbers.

In standard applications, the server side uses the operations listenOn and socketAccept to provide some service on a named socket, and the client side uses the operation connectToSocket to request a service.

Author: Michael Hanus

Version: December 2018

Summary of exported operations:

listenOn :: String -> IO Socket   
Creates a server side socket with a symbolic name.
socketAccept :: Socket -> IO (String,Handle)   
Returns a connection of a client to a socket.
waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))   
Waits until a connection of a client to a socket is available.
sClose :: Socket -> IO ()   
Closes a server socket.
socketName :: Socket -> String   
Returns a the symbolic name of a named socket.
connectToSocketRepeat :: Int -> IO a -> Int -> String -> IO (Maybe Handle)   
Waits for connection to a Unix socket with a symbolic name.
connectToSocketWait :: String -> IO Handle   
Waits for connection to a Unix socket with a symbolic name and return the handle of the connection.
connectToSocket :: String -> IO Handle   
Creates a new connection to an existing(!) Unix socket with a symbolic name.

Exported datatypes:


Socket

Abstract type for named sockets.

Constructors:


Exported operations:

listenOn :: String -> IO Socket   

Creates a server side socket with a symbolic name.

socketAccept :: Socket -> IO (String,Handle)   

Returns a connection of a client to a socket. The connection is returned as a pair consisting of a string identifying the client (the format of this string is implementation-dependent) and a handle to a stream communication with the client. The handle is both readable and writable.

waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))   

Waits until a connection of a client to a socket is available. If no connection is available within the time limit, it returns Nothing, otherwise the connection is returned as a pair consisting of a string identifying the client (the format of this string is implementation-dependent) and a handle to a stream communication with the client.

Example call:
(waitForSocketAccept socket timeout)
Parameters:
  • socket : a socket
  • timeout : milliseconds to wait for input (< 0 : no time out)

sClose :: Socket -> IO ()   

Closes a server socket.

socketName :: Socket -> String   

Returns a the symbolic name of a named socket.

Further infos:
  • solution complete, i.e., able to compute all solutions

connectToSocketRepeat :: Int -> IO a -> Int -> String -> IO (Maybe Handle)   

Waits for connection to a Unix socket with a symbolic name. In contrast to connectToSocket, this action waits until the socket has been registered with its symbolic name.

Example call:
(connectToSocketRepeat waittime action retries nameAtHost)
Parameters:
  • waittime : the time to wait before retrying (in milliseconds)
  • action : I/O action to be executed before each wait cycle
  • retries : number of retries before giving up (-1 = retry forever)
  • nameAtHost : the symbolic name of the socket (must be either of the form "name@host" or "name" where the latter is a shorthand for "name@localhost")
Returns:
Nothing (if connection is not possible within the given limits) or (Just h) where h is the handle of the connection

connectToSocketWait :: String -> IO Handle   

Waits for connection to a Unix socket with a symbolic name and return the handle of the connection. This action waits (possibly forever) until the socket with the symbolic name is registered.

Example call:
(connectToSocketWait nameAtHost)
Parameters:
  • nameAtHost : the symbolic name of the socket (must be either of the form "name@host" or "name" where the latter is a shorthand for "name@localhost")
Returns:
the handle of the connection (connected to the socket nameAtHost) which is both readable and writable

connectToSocket :: String -> IO Handle   

Creates a new connection to an existing(!) Unix socket with a symbolic name. If the symbolic name is not registered, an error is reported.

Example call:
(connectToSocket nameAtHost)
Parameters:
  • nameAtHost : the symbolic name of the socket (must be either of the form "name@host" or "name" where the latter is a shorthand for "name@localhost")
Returns:
the handle of the stream (connected to the socket nameAtHost) which is both readable and writable