Module "Socket.curry"

Library to support network programming with sockets. In standard applications, the server side uses the operations listenOn and socketAccept to provide some service on a socket, and the client side uses the operation connectToSocket to request a service.

Author: Michael Hanus

Version: February 2008


 Exported names:

Datatypes:
Socket

Functions:
connectToSocket | listenOn | listenOnFresh | sClose | socketAccept | waitForSocketAccept


 Summary of exported functions:

listenOn  :: Int -> IO Socket  deterministic 
          Creates a server side socket bound to a given port number.
listenOnFresh  :: IO (Int,Socket)  deterministic 
          Creates a server side socket bound to a free port.
socketAccept  :: Socket -> IO (String,Handle)  deterministic 
          Returns a connection of a client to a socket.
waitForSocketAccept  :: Socket -> Int -> IO (Maybe (String,Handle))  deterministic 
          Waits until a connection of a client to a socket is available.
sClose  :: Socket -> IO ()  deterministic 
          Closes a server socket.
connectToSocket  :: String -> Int -> IO Handle  deterministic 
          Creates a new connection to a Unix socket.

 Imported modules:

IO
Prelude
System

 Exported datatypes:

Socket

The abstract type of sockets.

Constructors:



 Exported functions:

listenOn :: Int -> IO Socket  deterministic 

Creates a server side socket bound to a given port number.


listenOnFresh :: IO (Int,Socket)  deterministic 

Creates a server side socket bound to a free port. The port number and the socket is returned.

Further infos:
  • externally defined

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

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))  deterministic 

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 ()  deterministic 

Closes a server socket.


connectToSocket :: String -> Int -> IO Handle  deterministic 

Creates a new connection to a Unix socket.

Example call:  (connectToSocket host port)

Parameters:
host - the host name of the connection
port - the port number of the connection
Returns:
the handle of the stream (connected to the port port@host) which is both readable and writable


Generated by CurryDoc (Version 0.4.1 of June 7, 2007) at Aug 28 15:26:00 2008