Safe Haskell | None |
---|---|
Language | Haskell2010 |
This is the same API as network-simple
with the difference
of working on SockAddr
instead of
.HostName
s
For a more detailed explanation check
Network.Simple.TCP
- connect :: (MonadIO m, MonadMask m) => SockAddr -> (Socket -> m r) -> m r
- connectFork :: MonadIO m => SockAddr -> (Socket -> IO ()) -> m ThreadId
- serve :: (MonadIO m, MonadMask m) => SockAddr -> (SockAddr -> Socket -> IO ()) -> m ()
- listen :: (MonadIO m, MonadMask m) => SockAddr -> (Socket -> m r) -> m r
- bind :: (MonadIO m, MonadMask m) => SockAddr -> m Socket
- acceptFork :: (MonadIO m, MonadCatch m) => Socket -> (SockAddr -> Socket -> IO ()) -> m ThreadId
- send :: MonadIO m => Socket -> ByteString -> m ()
- recv :: MonadIO m => Socket -> Int -> m ByteString
- close :: MonadIO m => SockAddr -> Socket -> m ()
- data Socket :: *
- data SockAddr :: *
Client side
:: (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.
:: 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
:: (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.
:: (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.
:: (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.