blob: 896763409e80762e91d42200c0b57094861dc5a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
module Main where
import SocketPrim
import BSD
import System
main =
getArgs >>= \ [host, port, message] ->
getProtocolNumber "tcp" >>= \ proto ->
socket AF_INET Stream proto >>= \ s ->
getHostByName host >>= \ (HostEntry _ _ _ haddrs) ->
connect s (SockAddrInet (mkPortNumber (read port))
(head haddrs)) >>
getPeerName s >>= \ (SockAddrInet _ haddr) ->
getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) ->
putStr ("Connected to : " ++ hname ++ "\n") >>
writeSocket s message >>
shutdown s ShutdownBoth >>
sClose s
|