module Main whereimport Network.Socket
import Control.Concurrentmain :: IO ()
main = do
sock <- socket AF_INET Stream 0
bindSocket sock (SockAddrInet 4242 iNADDR_ANY)
listen sock 10240
mainLoop sockmainLoop :: Socket -> IO ()
mainLoop sock = do
conn <- accept sock
forkIO $ runConn conn
mainLoop sockrunConn :: (Socket, SockAddr) -> IO ()
runConn (sock, tcp) = do
sms<-recv sock 1024
peeraddr <- getPeerName sock
putStrLn sms
runConn (sock, tcp)
本文haskell实现多线程服务器实例代码到此结束。要克服生活的焦虑和沮丧,得先学会做自己的主人。小编再次感谢大家对我们的支持!