RosettaCodeData/Task/Sockets/NetRexx/sockets.netrexx

29 lines
800 B
Plaintext

/* NetRexx */
options replace format comments java crossref symbols nobinary
import java.net.
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
parse arg host':'port':'message
if host = '' then host = 'localhost'
if port = '' then port = 256
if message = '' then message = 'hello socket world'
sendToSocket(host, port, message)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method sendToSocket(host, port, message) public static
do
sokt = Socket(host, port)
soks = sokt.getOutputStream()
soks.write((String message).getBytes())
soks.flush()
sokt.close()
catch ix = IOException
ix.printStackTrace()
end
return