0hc.net Menu
Home Overview
About Menu
Impressum

chat.hs

{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -no-recomp #-} module Main where import Network import System.IO import System.Environment import Control.Concurrent import AWin32Console -- Server: Args: Port -- Client: Args: IP Port main = g >> getArgs >>= \a-> f a f [x] = t $ get x f [x,y] = t $ write x y f _ = aPutStr "\ESC[0m\ESC[2J" >> getProgName >>= \x -> error $ x ++ " (port || IP port)" t f = catch f (\_ -> return Nothing) >> aPutStr "\ESC[0m\ESC[2J" g = aPutStr "\ESC[40m\ESC[2J\ESC[21f\ESC[1;44;37m\ESC[0J\ESC[1f\ESC[21f" write a b = withSocketsDo $ do hdl <- connectTo a (PortNumber (fromIntegral $ read b)) hSetBuffering hdl NoBuffering ter hdl get a = withSocketsDo $ do s <- listenOn (PortNumber (fromIntegral $ read a)) (hdl, hn, pn) <- accept s putStr hn >> putChar ' ' >> print pn hSetBuffering hdl NoBuffering ter hdl ter h = forkIO f >> g where f = do gL <- getLine a 0 gL hPutStrLn h gL f g = do gL <- hGetLine h a 1 gL g ll g = length g `div` 80 + 1 a 0 g = do let gN = ll g aPutStr $ "\ESC[21f\ESC[44m\ESC[4M\ESC[4L\ESC[1f\ESC[" ++ show gN ++ "M\ESC[40m\ESC[" ++ show (21-gN) ++ "f\ESC[" ++ show gN ++ "L\ESC[31m" ++ g ++ "\ESC[44;37m\ESC[21f" a 1 g = do let gN = ll g aPutStr $ "\ESC[s\ESC[1f\ESC[" ++ show gN ++ "M\ESC[40m\ESC[" ++ show (21-gN) ++ "f\ESC[" ++ show gN ++ "L\ESC[32m" ++ g ++ "\ESC[44;37m\ESC[u"
0hc.net    © 2001-2014 Harald Wolfsgruber