haskell实现多线程服务器实例代码

WBOY
Release: 2016-06-06 11:28:16
Original
1114 people have browsed it

代码如下:


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)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template