Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (24 sloc) 0.799 kB
-- Echo server program
module Main where
import Control.Monad (unless)
import Network.Socket hiding (recv)
import qualified Data.ByteString as S
import Network.Socket.ByteString (recv, sendAll)
main :: IO ()
main = withSocketsDo $
do addrinfos <- getAddrInfo
(Just (defaultHints {addrFlags = [AI_PASSIVE]}))
Nothing (Just "3000")
let serveraddr = head addrinfos
sock <- socket (addrFamily serveraddr) Stream defaultProtocol
bindSocket sock (addrAddress serveraddr)
listen sock 1
(conn, _) <- accept sock
talk conn
sClose conn
sClose sock
talk :: Socket -> IO ()
talk conn =
do msg <- recv conn 1024
unless (S.null msg) $ sendAll conn msg >> talk conn
Jump to Line
Something went wrong with that request. Please try again.