summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.hs30
1 files changed, 13 insertions, 17 deletions
diff --git a/main.hs b/main.hs
index bc62770..8ae5f54 100644
--- a/main.hs
+++ b/main.hs
@@ -33,8 +33,12 @@ warp_port = 10080
main :: IO ()
main = withSocketsDo $ do
- h <- connectTo server_hostname (PortNumber server_port)
- talk h `finally` hClose h
+ h <- connectTo server_hostname (PortNumber server_port)
+ (`finally` hClose h) $ do
+ hSetNewlineMode h universalNewlineMode
+ hSetBuffering h LineBuffering
+
+ handshake h >> race (fromServer h) (warp h) >>= print
handshake :: Handle -> IO ()
handshake h = do
@@ -42,21 +46,13 @@ handshake h = do
hPutStrLn h ("USER " ++ nick ++ " * 0 :" ++ nick)
hPutStrLn h ("JOIN " ++ chan)
-talk :: Handle -> IO ()
-talk h = do
- hSetNewlineMode h universalNewlineMode
- hSetBuffering h LineBuffering
- handshake h
- _ <- race fromServer (warp h)
- return ()
- where
- fromServer = forever $ do
- line <- hGetLine h
- --case line of
- if (isPrefixOf "PING" (pack line)) then
- hPutStrLn h (unpack (replace "PING" "PONG" (pack line)))
- else
- print line
+fromServer :: Handle -> IO ()
+fromServer h = forever $ do
+ line <- hGetLine h
+ if (isPrefixOf "PING" (pack line)) then
+ hPutStrLn h (unpack (replace "PING" "PONG" (pack line)))
+ else
+ print line
warp :: Handle -> IO ()
warp h =