remove unnecessary directory level
This commit is contained in:
parent
fdd4efe269
commit
60c164dbb0
20 changed files with 0 additions and 0 deletions
27
democlient.hs
Normal file
27
democlient.hs
Normal file
|
@ -0,0 +1,27 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Network.Socket hiding (send, sendTo, recv, recvFrom)
|
||||
import Network.Socket.ByteString
|
||||
import Control.Monad (forever)
|
||||
import System.IO (
|
||||
IOMode (ReadWriteMode)
|
||||
)
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.UTF8 as BSU
|
||||
|
||||
main = do
|
||||
sock <- socket AF_INET6 Datagram defaultProtocol
|
||||
setSocketOption sock IPv6Only 1
|
||||
-- lookup destination to get a SockAddr
|
||||
let hints = defaultHints { addrFamily = AF_INET6, addrSocketType = Datagram}
|
||||
destAddr <- addrAddress . head <$> getAddrInfo (Just hints) (Just "::1") (Just "7331")
|
||||
forever $ do
|
||||
inp <- getLine
|
||||
sendTo sock (BSU.fromString inp) destAddr
|
||||
print "Yeah, sent sth."
|
||||
-- important: as the socket is unconnected, it also accepts replies from a different source port
|
||||
(msg, fromAddr) <- recvFrom sock 65535
|
||||
putStrLn $ "Woop, received " ++ show msg ++ " from " ++ show fromAddr
|
||||
return ()
|
Loading…
Add table
Add a link
Reference in a new issue