netserver/newhwserv.hs
changeset 1341 86d7d5ab22a2
parent 1340 430d210d54ae
child 1350 99a921e292f4
equal deleted inserted replaced
1340:430d210d54ae 1341:86d7d5ab22a2
     9 import Control.Monad (forM, forM_, filterM, liftM)
     9 import Control.Monad (forM, forM_, filterM, liftM)
    10 import Maybe (fromMaybe)
    10 import Maybe (fromMaybe)
    11 import Data.List
    11 import Data.List
    12 import Miscutils
    12 import Miscutils
    13 import HWProto
    13 import HWProto
       
    14 import Opts
    14 
    15 
    15 acceptLoop :: Socket -> TChan ClientInfo -> IO ()
    16 acceptLoop :: Socket -> TChan ClientInfo -> IO ()
    16 acceptLoop servSock acceptChan = do
    17 acceptLoop servSock acceptChan = do
    17 	(cHandle, host, port) <- accept servSock
    18 	(cHandle, host, port) <- accept servSock
    18 	cChan <- atomically newTChan
    19 	cChan <- atomically newTChan
    85 	forkIO $ acceptLoop serverSocket acceptChan
    86 	forkIO $ acceptLoop serverSocket acceptChan
    86 	mainLoop serverSocket acceptChan [] []
    87 	mainLoop serverSocket acceptChan [] []
    87 
    88 
    88 
    89 
    89 main = withSocketsDo $ do
    90 main = withSocketsDo $ do
    90 	serverSocket <- listenOn $ Service "hedgewars"
    91 	flags <- opts
       
    92 	putStrLn $ "Listening on port " ++ show (getPort flags)
       
    93 	serverSocket <- listenOn $ PortNumber (getPort flags)
    91 	startServer serverSocket `finally` sClose serverSocket
    94 	startServer serverSocket `finally` sClose serverSocket