RPG IV Socket Tutorial

Scott Klement

This tutorial strives to teach network programming using sockets to AS/400 or iSeries programmers who use the RPG IV programming language.

It is assumed that the reader of this tutorial is already familiar with the RPG IV language, including the use of prototypes, subprocedures, service programs and pointers in an RPG IV environment.


Table of Contents
1. Introduction to TCP and Sockets
1.1. TCP/IP Concepts and Terminology
1.2. Overview of a TCP communications session
2. Looking up host names & services
2.1. Services and Ports
2.2. Host names and addresses
3. Socket API calls to create our first client program
3.1. The socket() API call
3.2. The connect() API call
3.3. The send() and recv() API calls
3.4. Translating from ASCII to EBCDIC
3.5. The close() API call
3.6. Our first client program
4. Improving our client program
4.1. improvement #1: header files
4.2. improvement #2: error handling
4.3. improvement #3: Creating a Read Line utility
4.4. improvement #4: Creating a Write Line utility
4.5. Packaging our utilities into a service program
4.6. improvement #5: Stripping out the HTTP response
4.7. improvement #6: Sending back escape messages
4.8. improvement #7: Displaying the data using DSPF
4.9. Our updated client program
5. Creating server programs
5.1. Introduction to server programs
5.2. The bind() API call
5.3. The listen() API call
5.4. The accept() API call
5.5. Our first server program
5.6. Testing server programs
5.7. Making our program end
5.8. The setsockopt() API call
5.9. The revised server program
6. Handling many sockets at once using select()
6.1. Overview of handling many clients
6.1.1. The "single program" approach:
6.2. The select() API call
6.3. Utility routines for working with select()
6.4. A combination client/server example
6.5. Blocking vs. non-blocking sockets
6.6. The fcntl() API call
6.7. A multi-client example of our server
6.8. Adding some refinements to our approach
6.9. A Chat Application
7. Handling many sockets by spawning jobs
7.1. Overview of job spawning approach
7.2. The takedescriptor() and givedescriptor() API calls
7.3. Retrieving the internal job id
7.4. Communicating the job information
7.5. Our server as a multi-job server
7.6. Working towards our next example
7.7. Validating a user-id and password
7.8. Running with the user's authority
7.9. A "generic server" example
7.10. Trying the "generic server" out
8. The User Datagram Protocol
8.1. Overview of using UDP
8.2. Creating a socket for use with UDP
8.3. The sendto() API call
8.4. The recvfrom() API call
8.5. Sample UDP server
8.6. Sample UDP client
8.7. Trying it out
Colophon