network-fancy-0.1.1: Networking support with a cleaner APISource codeContentsIndex
Network.Fancy
Contents
Address
Stream clients
Datagram clients
Servers
Other
Synopsis
type HostName = String
data Address
= IP HostName Int
| IPv4 HostName Int
| IPv6 HostName Int
| Unix FilePath
withStream :: Address -> (Handle -> IO a) -> IO a
connectStream :: Address -> IO Handle
connectDgram :: Address -> IO Socket
withDgram :: Address -> (Socket -> IO a) -> IO a
class StringLike string
recv :: StringLike string => Socket -> Int -> IO string
send :: StringLike string => Socket -> string -> IO ()
closeSocket :: Socket -> IO ()
data ServerSpec = ServerSpec {
address :: Address
reverseAddress :: Reverse
threading :: Threading
closeConnection :: Bool
recvSize :: Int
}
serverSpec :: ServerSpec
data Threading
= Threaded
| Inline
data Reverse
= ReverseNumeric
| ReverseName
streamServer :: ServerSpec -> (Handle -> Address -> IO ()) -> IO [ThreadId]
dgramServer :: StringLike packet => ServerSpec -> (packet -> Address -> IO [packet]) -> IO [ThreadId]
sleepForever :: IO ()
getCurrentHost :: IO HostName
data Socket
Address
type HostName = StringSource
data Address Source
Constructors
IP HostName IntHost name and port, either IPv4 or IPv6.
IPv4 HostName IntHost name and port, only IPv4.
IPv6 HostName IntHost name and port, only IPv6
Unix FilePathLocal unix socket, not supported on Windows.
show/hide Instances
Stream clients
withStream :: Address -> (Handle -> IO a) -> IO aSource
Open a stream (tcp) socket for the given block and close it afterwards.
connectStream :: Address -> IO HandleSource
Open a stream (tcp) socket.
Datagram clients
connectDgram :: Address -> IO SocketSource
Open a datagram (udp) socket.
withDgram :: Address -> (Socket -> IO a) -> IO aSource
Open a datagram (udp) socket for the given block and close it afterwards.
class StringLike string Source
show/hide Instances
recv :: StringLike string => Socket -> Int -> IO stringSource
Receive one chunk with given maximum size
send :: StringLike string => Socket -> string -> IO ()Source
Send the string as one chunk
closeSocket :: Socket -> IO ()Source
Close the socket specified.
Servers
data ServerSpec Source
Constructors
ServerSpec
address :: AddressAddress for the server. Use hostname "" to bind to all interfaces.
reverseAddress :: ReverseShould the address of connecting clients be suplied numerically or as a name to server function.
threading :: ThreadingHandle requests Inline or Threaded.
closeConnection :: BoolClose the client connection automatically after the ServerFun finishes.
recvSize :: IntBuffer size for receiving datagrams.
serverSpec :: ServerSpecSource
Default server specification
data Threading Source
Constructors
ThreadedRun each request in a separate thread without blocking the server loop.
InlineRun each request inline inside the request loop.
data Reverse Source
Constructors
ReverseNumericUse numeric addresses for peers.
ReverseNameResolve reverse names if possible for peers.
streamServer :: ServerSpec -> (Handle -> Address -> IO ()) -> IO [ThreadId]Source
Run a stream (tcp) server. The function does not block, use sleepForever if that is desired.
dgramServerSource
:: StringLike packet
=> ServerSpecServer specification
-> packet -> Address -> IO [packet]The server function is given a received packet and the Address of the peer. It returns a list of reply packets to send to that peer. Note that the list elements are invidual packets, not concatenated together.
-> IO [ThreadId]ThreadIds of the server listener processes.
Run a datagram (udp) server. The function does not block, use sleepForever if that is desired.
sleepForever :: IO ()Source
Sleep forever. Useful after a server.
Other
getCurrentHost :: IO HostNameSource
Get the current hostname.
data Socket Source
Produced by Haddock version 2.4.2