Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides convenience functions for interfacing io-streams
with raw tcp. the default receive buffer size is 4096. sending is unbuffered,
anything write into OutputStream
will be immediately send to underlying socket.
You should handle IOError
when you read/write these streams for safty.
Note, TCP_NODELAY
are enabled by default. you can use setSocketOption
to adjust.
- connectSocket :: HostName -> PortNumber -> IO Socket
- connect :: HostName -> PortNumber -> IO (InputStream ByteString, OutputStream ByteString, Socket)
- connectWithBufferSize :: HostName -> PortNumber -> Int -> IO (InputStream ByteString, OutputStream ByteString, Socket)
- withConnection :: HostName -> PortNumber -> (InputStream ByteString -> OutputStream ByteString -> Socket -> IO a) -> IO a
- bindAndListen :: PortNumber -> Int -> IO Socket
- accept :: Socket -> IO (InputStream ByteString, OutputStream ByteString, Socket, SockAddr)
tcp client
:: HostName | hostname to connect to |
-> PortNumber | port number to connect to |
-> IO Socket |
Convenience function for initiating an raw TCP connection to the given
(
combination.HostName
, PortNumber
)
Note that sending an end-of-file to the returned OutputStream
will not
close the underlying Socket connection; to do that, call:
SSL.shutdown
ssl SSL.Unidirectional
maybe (return ())close
$ SSL.sslSocket
ssl
on the returned SSL
object.
:: HostName | hostname to connect to |
-> PortNumber | port number to connect to |
-> IO (InputStream ByteString, OutputStream ByteString, Socket) |
connect to remote tcp server.
connectWithBufferSize Source #
:: HostName | hostname to connect to |
-> PortNumber | port number to connect to |
-> Int | tcp read buffer size |
-> IO (InputStream ByteString, OutputStream ByteString, Socket) |
connect to remote tcp server with a receive buffer size.
:: HostName | hostname to connect to |
-> PortNumber | port number to connect to |
-> (InputStream ByteString -> OutputStream ByteString -> Socket -> IO a) | Action to run with the new connection |
-> IO a |
Convenience function for initiating an SSL connection to the given
(
combination. The socket and SSL connection are
closed and deleted after the user handler runs.HostName
, PortNumber
)
Since: 1.2.0.0.
tcp server
bindAndListen :: PortNumber -> Int -> IO Socket Source #
bind and listen on port with a limit on connection count.
accept :: Socket -> IO (InputStream ByteString, OutputStream ByteString, Socket, SockAddr) Source #
accept a new connection from remote client, return a InputStream
/ OutputStream
pair,
a new underlying Socket
, and remote SockAddr
,you should call bindAndListen
first.
This function will block current thread if there's no connection comming.