



say "SERVER (ooRexx): program started."
/* create server socket listening on port 8888 */
srvSock=.bsf~new("java.net.ServerSocket", 5000)
say "SERVER (ooRexx): starting to accept clients..."
socket2client=srvSock~accept -- accept client, returns socket to client
say "SERVER (ooRexx): client" pp(socket2client~toString) "accepted."
/* get data from the client */

call syssleep 2

b=.bsf~bsf.createArray('byte.class', 2048) -- create a "byte"-array
received=socket2client~getInputStream~read(b) -- returns number of bytes read
/* turn received byte array to Rexx string */
say "SERVER (ooRexx): data received from client:" time() " "pp(BsfRawBytes(b,received))
/* send data to client */
os=socket2client~getOutputStream

call syssleep 2

Nachricht_Server="Hallo Client, ich bin dein Server"
say "SERVER (ooRexx): sending" pp(Nachricht_Server) "to client..."
socket2client~getOutputStream~write(BsfRawBytes(Nachricht_Server)) -- turn Rexx string to byte array

call syssleep 2

b=.bsf~bsf.createArray('byte.class', 2048) -- create a "byte"-array
received=socket2client~getInputStream~read(b) -- returns number of bytes read
/* turn received byte array to Rexx string */
say "SERVER (ooRexx): data received from client:" time() " "pp(BsfRawBytes(b,received))
/* send data to client */
os=socket2client~getOutputStream

call syssleep 2

Nachricht_Server2="Kein Problem. Auf eine gute Zusammenarbeit"
say "SERVER (ooRexx): sending" pp(Nachricht_Server2) "to client..."
socket2client~getOutputStream~write(BsfRawBytes(Nachricht_Server2)) -- turn Rexx string to byte array

call syssleep 2

say "SERVER (ooRexx): program ended."
::requires BSF.CLS