haskell实现多线程服务器实例代码
代码如下:
module Main where import Network.Socket import Control.Concurrent main :: IO () main = do sock <- socket AF_INET Stream 0 bindSocket sock (SockAddrInet 4242 iNADDR_ANY) listen sock 10240 mainLoop sock mainLoop :: Socket -> IO () mainLoop sock = do conn <- accept sock forkIO $ runConn conn mainLoop sock runConn :: (Socket, SockAddr) -> IO () runConn (sock, tcp) = do sms<-recv sock 1024 peeraddr <- getPeerName sock putStrLn sms runConn (sock, tcp)
相关推荐
insularisland 2020-04-20
瓜牛呱呱 2020-11-12
starinshy 2020-11-10
farewellpoem 2020-11-09
huichen 2020-10-13
WenSenli 2020-10-12
lhtzbj 2020-08-13
cuiweisaidelike 2020-08-02
comeonxueRong 2020-08-02
learnpy 2020-07-19
kyelu 2020-07-09
yunfeitian 2020-07-05
zhoujiyu 2020-06-28
TreasureZ 2020-06-25
三动 2020-06-21
jvm 2020-06-14
举 2020-06-14