HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestreamly-0.10.1Haskell2010

Streamly.Network.Inet.TCP

Combinators to build Inet/IPv4/TCP clients and servers.

Example1 expression
import qualified Streamly.Network.Inet.TCP as TCP

Examples

Following is a short example of a concurrent echo server.

Example11 expressions
import Control.Monad.Catch (finally)import Data.Function ((&))import Network.Socket (Socket)import qualified Network.Socket as Netimport qualified Streamly.Data.Fold as Foldimport qualified Streamly.Data.Stream.Prelude as Streamimport qualified Streamly.Network.Inet.TCP as TCPimport qualified Streamly.Network.Socket as Socket:{main :: IO ()main =      TCP.accept 8091                            -- Stream IO Socket    & Stream.parMapM id (handleExceptions echo)  -- Stream IO ()    & Stream.fold Fold.drain                     -- IO ()    where    echo :: Socket -> IO ()    echo sk =          Socket.readChunksWith 32768 sk      -- Stream IO (Array Word8)        & Stream.fold (Socket.writeChunks sk) -- IO ()    handleExceptions :: (Socket -> IO ()) -> Socket -> IO ()    handleExceptions f sk = finally (f sk) (Net.close sk):}
  • 10 values
  • Packagestreamly-0.10.1
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTCP.hs

Accept Connections

0 declarations

Streams

valueaccept :: MonadIO m => PortNumber -> Stream m Socket
#

Start a TCP stream server that binds on the IPV4 address 0.0.0.0 and listens for TCP connections from remote hosts on the specified server port. The server generates a stream of connected sockets.

Example1 expression
accept = TCP.acceptOnAddr (0,0,0,0)

Pre-release

Like accept but binds on the localhost IPv4 address 127.0.0.1. The server can only be accessed from the local host, it cannot be accessed from other hosts on the network.

Example1 expression
acceptLocal = TCP.acceptOnAddr (127,0,0,1)

Pre-release

Unfolds

Like acceptorOnAddr but binds on the IPv4 address 0.0.0.0 i.e. on all IPv4 addresses/interfaces of the machine and listens for TCP connections on the specified port.

Example1 expression
acceptor = Unfold.first (0,0,0,0) TCP.acceptorOnAddr

Like acceptor but binds on the localhost IPv4 address 127.0.0.1. The server can only be accessed from the local host, it cannot be accessed from other hosts on the network.

Example1 expression
acceptorLocal = Unfold.first (127,0,0,1) TCP.acceptorOnAddr

Connect to Servers

1 declaration

Deprecated

2 declarations