network-simple-sockaddr-0.2: network-simple for resolved addresses

Safe HaskellNone
LanguageHaskell2010

Network.Simple.SockAddr

Contents

Description

This is the same API as network-simple with the difference of working on SockAddr instead of HostNames.

For a more detailed explanation check Network.Simple.TCP

Synopsis

Client side

connect Source

Arguments

:: (MonadIO m, MonadMask m) 
=> SockAddr

Server address.

-> (Socket -> m r)

Computation taking the socket connection socket.

-> m r 

Connect to a server and use the connection.

The connection socket is closed when done or in case of exceptions.

connectFork Source

Arguments

:: MonadIO m 
=> SockAddr

Server address.

-> (Socket -> IO ())

Computation taking the socket connection socket.

-> m ThreadId 

Like connect but fork the connection in a different thread.

Server side

serve Source

Arguments

:: (MonadIO m, MonadMask m) 
=> SockAddr

Address to bind to.

-> (SockAddr -> Socket -> IO ())

Computation to run in a different thread once an incoming connection is accepted. Takes the the remote end address and the connection socket.

-> m () 

Start a server that accepts incoming connections and handles them concurrently in different threads.

Any acquired network resources are properly closed and discarded when done or in case of exceptions.

listen Source

Arguments

:: (MonadIO m, MonadMask m) 
=> SockAddr

Address to bind to.

-> (Socket -> m r)

Computation taking the listening socket.

-> m r 

Bind a listening socket and use it.

The listening socket is closed when done or in case of exceptions.

bind :: (MonadIO m, MonadMask m) => SockAddr -> m Socket Source

Obtain a Socket bound to the given SockAddr.

The obtained Socket should be closed manually using close when it's not needed anymore.

Prefer to use listen if you will be listening on this socket and using it within a limited scope, and would like it to be closed immediately after its usage or in case of exceptions.

acceptFork Source

Arguments

:: (MonadIO m, MonadCatch m) 
=> Socket

Listening and bound socket.

-> (SockAddr -> Socket -> IO ())

Computation to run in a different thread once an incoming connection is accepted. Takes the remote end address and connection socket.

-> m ThreadId 

Accept a single incoming connection and use it in a different thread.

The connection socket is closed when done or in case of exceptions.

Utils

send :: MonadIO m => Socket -> ByteString -> m () Source

Writes the given bytes to the socket.

recv :: MonadIO m => Socket -> Int -> m ByteString Source

Read up to a limited number of bytes from a socket.

close :: MonadIO m => SockAddr -> Socket -> m () Source

Close the Socket and unlinks the SockAddr for Unix sockets.

Re-exported from Network.Socket

data Socket :: *