tcp-streams-0.2.1.0: One stop solution for tcp client and server with tls support.

Safe HaskellNone
LanguageHaskell2010

System.IO.Streams.TCP

Contents

Description

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 safety. Note, TCP_NODELAY are enabled by default. you can use setSocketOption to adjust.

Synopsis

tcp client

connectSocket Source #

Arguments

:: HostName

hostname to connect to

-> PortNumber

port number to connect to

-> IO Socket 

Convenience function for initiating an raw TCP connection to the given (HostName, PortNumber) combination.

Note that sending an end-of-file to the returned OutputStream will not close the underlying Socket connection.

connect Source #

Arguments

:: HostName

hostname to connect to

-> PortNumber

port number to connect to

-> IO (InputStream ByteString, OutputStream ByteString, Socket) 

connect to remote tcp server.

You may need to use bracket pattern to enusre Socket 's safety.

connectWithBufferSize Source #

Arguments

:: 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.

withConnection Source #

Arguments

:: 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 TCP connection to the given (HostName, PortNumber) combination. The socket will be closed and deleted after the user handler runs.

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.