I have a small server written in Haskell, when I send something to him, he must evaluate whether the sent content matches the password in the auth function, but it is never True. I see that the sent message has passed because it is printed in 'putStrLn msg'. I tried several things, different functions, the use of "case" in haskell, .... I'm not sure what I'm doing wrong, is there just no string comparison?
Thanks in advance!
import Network
import Control.Concurrent
import System.IO
import Data.List
import Control.Monad
main :: IO ()
main = withSocketsDo $ do
sock <- listenOn $ PortNumber 4242
loop sock
loop :: Socket -> IO ()
loop sock = do
(h,_,_) <- accept sock
forkIO $ auth h
loop sock
auth :: Handle -> IO ()
auth h = do
msg <- hGetLine h
putStrLn msg
when (msg == "password") $ do
server h
server :: Handle -> IO ()
server h = do
hPutStr h "connected"
putStrLn "connected"
msg <- hGetLine h
putStrLn msg
hClose h
source
share