TCP/IP sockets code in REXX script (long) - client.CMD (1/1) 
Author Message
 TCP/IP sockets code in REXX script (long) - client.CMD (1/1)

Quote:

>LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
>KioqKioqKioqKg0KICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
<....snip.....>
>ZShTb2NrZXQpDQpjYWxsIGluZm9ybSAiU29ja0Nsb3NlIHJldHVybnMgInJjLCAiY2xpZW50Ig0K
>DQpyZXR1cm4gMA0KDQpVaE9oOg0KaWYgU29ja2V0IFw9ICJTT0NLRVQiIHRoZW4gcmMgPSBTb2Nr
>Q2xvc2UoU29ja2V0KQ0KcmV0dXJuIDENCg0KGg==

That wasn't long.   It was only 67 lines.  Couldn't _read_ any of
them, but there weren't too many....

Frank Clarke
Tampa Area REXX Programmers' Alliance
Member of the REXX Language Association
Join us at http://www.*-*-*.com/
(Remove the currency symbol before replying.)



Mon, 07 Aug 2000 03:00:00 GMT  
 TCP/IP sockets code in REXX script (long) - client.CMD (1/1)

Quote:

>That wasn't long.   It was only 67 lines.  Couldn't _read_ any of
>them, but there weren't too many....

Well, you need that base64 decoding script we were talking about just the
other day. :-)

Still, it strikes me as rather stupid that there are quite a lot of
applications out there which will encode an attachment like this even
if it contains pure text.  It multiplies the size of the attachment by
4/3 and annoys readers who don't have base64 decoders built into their
software.

Here's a trivial base64 filter (runs quite slowly but didn't take long
to write).

validchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
validchars=validchars || '0123456789+/='

input=''
eof=0
call on notready name eof
do until input==''
   do while length(input)<5 & right(input,1)\=='=' & \eof
      input=input ||,
            space(translate(linein(),validchars,validchars xrange()),,0)
   end
   bits=''
   do b=1 to 4
      parse var input char +1 input
      if char=='' | char=='=' then do
         bits=left(bits,8*(b-2))
         input=''
         leave
      end
      bits=bits||right(d2b(verify(validchars,char,'m')-1),6)
   end
   call charout , x2c(b2x(bits))
end
exit
eof: eof=1; return
--

------ http://www.comlab.ox.ac.uk/oucl/users/ian.collier/imc.html

New to this group?  Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .



Tue, 08 Aug 2000 03:00:00 GMT  
 TCP/IP sockets code in REXX script (long) - client.CMD (1/1)

Quote:


>That wasn't long.   It was only 67 lines.  Couldn't _read_ any of
>them, but there weren't too many....

>Frank Clarke
>Tampa Area REXX Programmers' Alliance
>Member of the REXX Language Association
>Join us at http://www.rexxla.org
>(Remove the currency symbol before replying.)

Apologies to those who had trouble reading the source code:

/******************************************************************
 *                                                                *
 *  Application: SHIPBACK                                         *
 *  Script:      SHIPSERVER                                       *
 *  Argument:                                                     *
 *  Machine:                                                      *
 *                                                                *
 *  Description: back end for Beaver Dam shipping                 *
 *                                                                *
 *                                                                *
 *  REVISION HISTORY                                              *
 *                                                                *
 *  Date        Who   Description of change                       *
 *  ------------------------------------------------------------  *
 *  01-30-1998  ghh   Original                                    *
 *  02-17-1998  ghh   try and avoid "invalid session ID"          *
 ******************************************************************/

if RxFuncQuery("SockLoadFuncs")
  then rc = RXFuncAdd("SockLoadFuncs", "rxSock", "SockLoadFuncs")
rc = SockLoadFuncs()
rc = SockInit()

ServerSocket = SockSocket("AF_INET", "SOCK_STREAM", "IPPROTO_TCP")
if ServerSocket = -1 then do
  call inform "Can't create server socket", "server: cannot continue"
  signal UhOh
end
else do
  call inform "SockSocket returns descriptor "ServerSocket, "server"
end

prc = ASK("Port number: ", "Ship Server", "1953")
ServerAddress._family = "AF_INET"
ServerAddress._port = prc
ServerAddress._addr = "INADDR_ANY"
rc = SockBind(ServerSocket, ServerAddress._)
if rc = -1 then do
  call inform "Can't bind server socket to port "prc, "server: cannot continue"
  rc = SockClose(ServerSocket)
  signal UhOh
end
else call inform "SockBind() returns" rc, "server"

rc = SockListen(ServerSocket, 5)
if rc = -1 then do
  call inform "Can't create connection queue", "server: cannot continue"
  rc = SockClose(ServerSocket)
  signal UhOh
end
else call inform "SockListen() returns" rc, "server"

ClientAddress._family = "AF_INET"
ClientAddress._port = prc
ClientAddress._addr = "INADDR_ANY"
ClientSocket = SockAccept(ServerSocket, ClientAddress._)
/* (returns only on a client request) */
call inform "SockAccept() returns descriptor" ClientSocket, "server"

rc = SockGetPeerName(ClientSocket, ClientAddress._)
if rc = -1
  then call inform "SockGetPeerName() failed", "server"
else do
  rc = SockGetHostByAddr(ClientAddress._addr, host._)
  if rc = 0 then do
    call inform "client is on" ClientAddress._addr, "server: SockGetHostByAddr() failed"
  end
  else do
    msg = "client name:" host._name || '0d'x
    do i = 1 to host._alias.0
      msg = msg || "client alias:" host._alias.i || '0d'x
    end
    do i = 1 to host._addr.0
      msg = msg || "client address:" host._addr.i || '0d'x
    end
    call inform msg, "server"
  end
end

do forever
  rc = SockRecv(ClientSocket, Buffer, 256)
  if rc = -1 then do
    call inform "SockRecv() failed", "server"
    rc = SockClose(ClientSocket)
    rc = SockClose(ServerSocket)
    signal UhOh
  end
  else do
    /* return code is number of characters received */
    call inform "client message:" Buffer, "server"
  end

  if translate(Buffer) = "QUIT" then leave

  /* for testing, just echo the buffer back again */
  rc = SockSend(ClientSocket, Buffer)
  if rc = -1 then do
    call inform "SockSend() failed", "server"
    rc = SockClose(ClientSocket)
    rc = SockClose(ServerSocket)
    signal UhOh
  end
  else do
    nop /* return code is number of characters sent */
  end
  drop Buffer
end

call inform "closing server socket "ServerSocket, "server"
rc = SockShutDown(ServerSocket, 2)  /* end communication, both directions */
call inform "SockShutDown returns "rc" on server socket", "server"
rc = SockClose(ServerSocket)
call inform "SockClose returns "rc" closing server socket", "server"

call inform "closing client socket "ClientSocket, "server"
rc = SockShutDown(ClientSocket, 2)  /* end communication, both directions */
call inform "SockShutDown returns "rc" on client socket", "server"
rc = SockClose(ClientSocket)
call inform "SockClose returns "rc" closing client socket", "server"

return 0

UhOh:
if ServerSocket \= "SERVERSOCKET" then rc = SockClose(ServerSocket)
if ClientSocket \= "CLIENTSOCKET" then rc = SockClose(ClientSocket)
return 1

/******************************************************************
 *                                                                *
 *  Application: SHIPBACK                                         *
 *  Script:      SHIPCLIENT                                       *
 *  Argument:                                                     *
 *  Machine:                                                      *
 *                                                                *
 *  Description: front end for Beaver Dam shipping                *
 *                                                                *
 *                                                                *
 *  REVISION HISTORY                                              *
 *                                                                *
 *  Date        Who   Description of change                       *
 *  ------------------------------------------------------------  *
 *  01-30-1998  ghh   Original                                    *
 *  02-17-1998  ghh   try and avoid "invalid session ID"          *
 *                                                                *
 ******************************************************************/

rc = RXFuncAdd("SysSleep", "RexxUtil", "SysSleep")
if RxFuncQuery("SockLoadFuncs")
  then rc = RXFuncAdd("SockLoadFuncs", "rxSock", "SockLoadFuncs")
rc = SockLoadFuncs()
rc = SockInit()

HostAddress = SockGetHostId()
call inform "running on address "HostAddress, "client"

Server = "192.168.0.103"  /* can also use hostname */

rc = SockGetHostByName(Server, host._)
if rc = 0 then do
  drop host._
  rc = SockGetHostByAddr(Server, host._)
  if rc = 0 then do
    call inform "Can't resolve host name '" || Server || "'", "client: cannot continue"
    signal UhOh
  end
end
msg = "server name:" host._name || '0d'x
do i = 1 to host._alias.0
  msg = msg || "server alias:" host._alias.i || '0d'x
end
do i = 1 to host._addr.0
  msg = msg || "server address:" host._addr.i || '0d'x
end
call inform msg, "client"

Socket = SockSocket("AF_INET", "SOCK_STREAM", "IPPROTO_TCP")
if Socket = -1 then do
  call inform "SockSocket() failed", "client"
  signal UhOh
end
else call inform "SockSocket() returns descriptor" Socket, "client"

prc = ASK("Port number: ", "Ship Client", "1953")
ServerAddress._family = "AF_INET"
ServerAddress._port = prc
ServerAddress._addr = host._addr.1
rc = SockConnect(Socket, ServerAddress._)
if rc = -1 then do
  call inform "SockConnect() failed", "client"
  signal UhOh
end
else call inform "SockConnect() returns" rc, "client"

msg = "Message no. "; msgno = 1
do forever
  SendBuffer = msg || msgno; msgno = msgno + 1
  if msgno > 5 then SendBuffer = "QUIT"
  call inform "sending "SendBuffer, "client"
  rc = SockSend(Socket, SendBuffer)
  if rc = -1 then do
    call inform "SockSend() failed", "client"
    signal UhOh
  end
  else do
    nop /* return code is number of characters sent */
  end

  if SendBuffer = "QUIT" then leave

  rc = SockRecv(Socket, RecvBuffer, 256)
  if rc = -1 then do
    call inform "SockRecv() failed", "client"
    signal UhOh
  end
  else do
    /* return code is number of characters received */
    call inform "server response:" RecvBuffer, "client"
  end
  drop SendBuffer; drop RecvBuffer
  call SysSleep 2
end

rc = SockShutDown(Socket, 2)  /* end communication, both directions */
call inform "SockShutDown returns "rc, "client"

rc = SockClose(Socket)
call inform "SockClose returns "rc, "client"

return 0

UhOh:
if Socket \= "SOCKET" then rc = SockClose(Socket)
return 1

--
____________________________________________________________

Programmer/Analyst                       phone: 414.263.8827
Weyco Group, Inc.                          fax: 414.263.8808



Tue, 08 Aug 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TCP/IP sockets code in REXX script (long) - client.CMD (0/1)

2. TCP/IP sockets code in REXX script (long) - server.CMD (0/1)

3. TCP IP, client and server socket

4. REXX for OS/2 TCP/IP Socket API question

5. REXX TCP/IP Socket Interface For Netview

6. (long) Object Rexx: Socket, Client, Server Framework

7. need sample mvs rexx socket server/client code

8. C5 - TCP/IP Client/Server and DirectX Questions

9. TCP/IP server & client in CW2xxxx

10. Interest in TCP/Ip Server & Client

11. Client - Server slow tcp/ip...

12. CLIENT (Windows 3.1 or 95 or NT) to MVS-CICS via TCP/IP or other gateway

 

 
Powered by phpBB® Forum Software