gameServer/NetRoutines.hs
changeset 3500 af8390d807d6
parent 3435 4e4f88a7bdf2
child 3502 ad38c653b7d9
equal deleted inserted replaced
3499:66eba4e41b91 3500:af8390d807d6
     1 {-# LANGUAGE ScopedTypeVariables #-}
     1 {-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
     2 module NetRoutines where
     2 module NetRoutines where
     3 
     3 
     4 import Network.Socket
     4 import Network.Socket
     5 import System.IO
     5 import System.IO
     6 import Control.Concurrent.Chan
     6 import Control.Concurrent.Chan
    16     Exception.handle
    16     Exception.handle
    17         (\(_ :: Exception.IOException) -> putStrLn "exception on connect") $
    17         (\(_ :: Exception.IOException) -> putStrLn "exception on connect") $
    18         do
    18         do
    19         (sock, sockAddr) <- Network.Socket.accept servSock
    19         (sock, sockAddr) <- Network.Socket.accept servSock
    20 
    20 
    21         cHandle <- socketToHandle sock ReadWriteMode
       
    22         hSetBuffering cHandle LineBuffering
       
    23         clientHost <- sockAddr2String sockAddr
    21         clientHost <- sockAddr2String sockAddr
    24 
    22 
    25         currentTime <- getCurrentTime
    23         currentTime <- getCurrentTime
    26 
    24 
    27         sendChan' <- newChan
    25         sendChan' <- newChan
    28 
    26 
    29         let newClient =
    27         let newClient =
    30                 (ClientInfo
    28                 (ClientInfo
    31                     sendChan'
    29                     sendChan'
    32                     cHandle
    30                     sock
    33                     clientHost
    31                     clientHost
    34                     currentTime
    32                     currentTime
    35                     ""
    33                     ""
    36                     ""
    34                     ""
    37                     False
    35                     False