养成好习惯是储存健康,放纵不良是透支生命。我们一生之中,要牢记和要忘记的东西一样多。
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实现多线程服务器实例代码到此结束。要克服生活的焦虑和沮丧,得先学会做自己的主人。小编再次感谢大家对我们的支持!