Created
July 1, 2020 14:14
-
-
Save soupi/1cc542a97b3e4c6cf0f7a577e8b4fb24 to your computer and use it in GitHub Desktop.
Echo server/client haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Control.Monad (forever, unless) | |
import qualified Data.ByteString.Char8 as C | |
import Network.Socket | |
import Network.Run.TCP (runTCPClient) | |
import Network.Socket.ByteString (recv, sendAll) | |
import System.IO (hFlush, stdout) | |
main :: IO () | |
main = | |
runTCPClient "127.0.0.1" "8686" $ \s -> forever $ do | |
putStr "> " | |
hFlush stdout | |
line <- C.getLine | |
sendAll s line | |
msg <- recv s 1024 | |
C.putStrLn msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Control.Monad (forever, unless) | |
import qualified Data.ByteString as S | |
import Network.Socket | |
import Network.Run.TCP (runTCPServer) | |
import Network.Socket.ByteString (recv, sendAll) | |
main :: IO () | |
main = | |
runTCPServer Nothing "8686" (forever . talk) | |
where | |
talk s = do | |
msg <- recv s 1024 | |
unless (S.null msg) $ | |
sendAll s msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment