rexx-things/samples/oorexx/scclient.rex
2025-03-12 20:50:48 +00:00

43 lines
1.1 KiB
Rexx
Executable File

#!/usr/bin/env rexx
/* A simple socket client using the Socket class */
/* instantiate an instance of the socket class */
sock = .socket~new()
/* instantiate an instance of the inetaddress class
with the host information of the server we will
contact: localhost and port 50010 */
host = .inetaddress~new('localhost', '50010')
/* connect to the server */
if sock~connect(host) < 0 then do
say 'Connect failed:' sock~errno
exit
end
say 'type "X" to exit'
do forever
call charout , 'Send To Server: '
parse pull message
if message~upper() = 'X' then leave
/* send message to server */
if sock~send(message) < 0 then do
say 'Send failed:' sock~errno
leave
end
/* get message from server */
ret = sock~recv(1024)
if ret = .nil then do
say 'Recv failed:' sock~errno
leave
end
say 'Server responded:' ret
end
/* close the socket connection */
if sock~close() < 0 then
say 'SockClose failed:' sock~errno
::requires 'socket.cls'