In order to try out our sample UDP programs, we'll first have to compile them. Let's build the server first:
CRTBNDRPG UDPSERVER SRCFILE(SOCKTUT/QRPGLESRC) DBGVIEW(*LIST)
Now the client:
CRTBNDRPG UDPCLIENT SRCFILE(SOCKTUT/QRPGLESRC) DBGVIEW(*LIST)
CRTCMD CMD(UDPCLIENT) PGM(SOCKTUT/UDPCLIENT) SRCFILE(SOCKTUT/QCMDSRC)
Start the server by typing this:
SBMJOB CMD(CALL UDPSERVER) JOBQ(QSYSNOMAX) JOB(UDP)
And then you can try out the client, like this:
UDPCLIENT RMTSYS('127.0.0.1') USERID(klemscot) MSG('this is a fine test!')
At first glance, this program doesn't seem very practical. After all, you could've done the same thing with the SNDMSG command. However, if you now go to another AS/400, and put our newly built UDPCLIENT on that machine, you can use it to send messages over the network! or even over the internet!
Likewise, if you wrote a message client (similar to UDPCLIENT) to run on your PC, you could send messages from there.
Of course, this is still not very practical :) It is, however, a simple example of how to use UDP datagrams. If you have ideas for a better UDP program, I certainly encourage you to go ahead and experiment!
This concludes my socket tutorial (for now, anyway) I hope you found it enlightening.
If you've found any mistakes in the tutorial, or anything that you feel is not explained as well as it could be, please send me an E-mail. I'd like this tutorial to be the best that it can be -- and your suggestions will help to make that happen!