代码如下:


module Main where

import Network.Socket
import Control.Concurrent

main :: IO ()
main = do
sock bindSocket sock (SockAddrInet 4242 iNADDR_ANY)
listen sock 10240
mainLoop sock

mainLoop :: Socket -> IO ()
mainLoop sock = do
conn forkIO $ runConn conn
mainLoop sock

runConn :: (Socket, SockAddr) -> IO ()
runConn (sock, tcp) = do
sms peeraddr putStrLn sms
runConn (sock, tcp)

08-18 11:41