Home > Webcasts > Previous Event
EMAIL THIS
WebcastsPrevious Webcasts
> Sockets Programming with RPG & Visual Basic
When: Apr 24, 2001
Speaker: Chris Peters , client/server application specialist, Evergreen Interactive Systems.
Topic: Discover how-to techniques to get the most out of sockets technology, and key TCP/IP tools to help you conquer your toughest Internet development projects. Plus gain ILE insight to incorporate external functions, and much more!
Transcript:

Moderator: Thank you for joining us for our Live Expert Q&A session with Chris Peters on Sockets Programming with RPG & Visual Basic. Chris is a client/server application specialist at Evergreen Interactive Systems (http://www.evergreeninteractive.com) and author of the AS/400 TCP/IP Handbook and AS/400 Client/Server Programming with Visual Basic 5.0.

Moderator: Chris will be talking today about how to get the most out of sockets technology, and key TCP/IP tools to help you with your Internet development projects. To help you with your own projects, Chris has made available files that you can download today. In this download you'll find excerpts from his books and some sample programs. Click on Tcp/Ip Documentation & Code (434KB) to get the files.

jason.marshall945150 : First of all, what are sockets?

Chris_Peters : A socket is a software interface that allows a program to link to another program in a physical IP communications network. Each TCP/IP-enabled computer has 65536 sockets available for TCP communications with other hosts. The sockets are really just logical ports, created by software, and all run over the same physical TCP/IP link. By agreement, certain socket numbers are assigned to services available on every TCP/IP host. Services such as FTP (File Transfer Protocol), which runs over socket 21, and telnet, which runs over socket 23. In general, sockets numbered 1 through 1023 are reserved for TCP/IP host services and should not be used for your applications.

cketcher411619: What do you mean by "sockets programming"?

Chris_Peters : I mean creating a client/server application. That is, writing two programs -- one on a PC and one on the AS/400 -- that work together, pretty much like the AS/400 and a display file work together. The programs interact over a communications link such as Ethernet, Token Ring, the Internet, etc.

mtripp794342: Why would using sockets programming be better than, say, using the ODBC driver or ADO?

Chris_Peters : It isn't always better - it depends on the application you're developing. For simple things you can usually get adequate results with the two-tier methods (ODBC/ADO). For more complex applications, using sockets gives you the ability to write the server program yourself, much like you would with a traditional green-screen program. Your server program can then access all of the 400's resources in the usual ways. It's not uncommon for a production-quality AS/400 server program to access 25 or 30 files. Applications like that are best written with a three-tier method such as sockets.

mderby937257: What about performance when using sockets?

Chris_Peters : Coding to the TCP/IP sockets support layer gives you the fastest possible response time and throughput because you're using the same communications support layer the TCP/IP utilities, such as FTP, are using.

mcohodas513352: What other utilities use sockets?

Chris_Peters : Many well-known TCP/IP utilities run over sockets, such as Telnet (5250 emulation runs over Telnet,) SMTP, POP, SNMP, etc. These common utilities run over ports 1-1024 (called "well-known" sockets). When you write a sockets application, you should avoid using sockets numbered under 1024.
Port names Port Number Service Descriptions
Echo 7 echoes whatever you send
discard 9 discards whatever you send
daytime 13 returns the destination machine's local time
qotd 17 returns the "quote of the day" for that machine
chargen 19 returns a test stream of characters
ftp 21 File Transfer Protocol port
smtp 25 Simple Mail Transfer Protocol port
finger 79 Finger protocol port
http 80 Web server port
pop3 110 POP version 3 port

bvigil64651: How many sockets are there?

Chris_Peters : A socket is just a number used to identify a communications session. There are about 65,000 sockets for each of the two protocol groups - TCP (Transaction Communications Protocol) and UDP (User Datagram Protocol.) When you write sockets c/s applications you'll most likely be using TCP, which establishes a transactional link between the participants.

mikewhale104758: Under what jobs on the 400 do socket programs run?

Chris_Peters : Most of the TCP/IP sockets jobs are running in the QSYSWRK subsystem. There may also be some HTTP jobs running in their own subsystem, as well. You can tell what they are, generally, by the names (QTFTP... are FTP jobs, and you'll see Telnet there, etc.) If you create your own sockets server it will probably run in qsyswrk, as well...

bsheets782756: How do I access the sockets support from within an RPG program?

Chris_Peters : Sockets support is accessed through IBM APIs. These APIs are intended to be used with the C programming language, but since the development of ILE they can be accessed from RPG. This makes it possible for a traditional AS/400 programmer to develop a production-quality client/server application in much the same manner as they would develop a green-screen program.

steve_at_oxford923516 : Why should I code a client/server application like a green-screen program?

Chris_Peters : All the best features of the PC are used (like the GUIs and access to the PC's other applications - Excel, Word, e-mail) while retaining the AS/400's best features (central data storage and management, security, processing power).

brama959789: What do I have to code on the PC side?

Chris_Peters : You have to know enough about a client language (like Visual Basic) to put up the screens and collect the information from the user (again, much like a display file program.) The actual communications through sockets from the client side is relatively easy because there are custom controls available. A custom control is a wrapper for low-level communications processes.

cgagne783843: What do I have to code on the AS/400 side?

Chris_Peters : The AS/400 side is not so easy. To code to the sockets support layer, you have to learn how to use a half-dozen or so sockets APIs. Here are some function names and their meanings: socket -- create a descriptor for use in network communication; connect -- connect to a remote peer; closesocket -- terminate communication and deallocate a descriptor; bind -- bind a local IP address and protocol port to a socket; listen -- place the socket in passive mode and set the number of incoming TCP connections the system will queue (server); accept -- accept the next incoming connection (server); recv -- acquire incoming data from a stream connection or the next incoming message; send -- send outgoing data or a message; setsockopt -- change the options for a socket.

cdoss72709: How does the server handle multiple requestors?

Chris_Peters : On the 400, there's a main server program that "listens" over a well-known socket (at least well-known to your clients, but not in the 1-1024 range) for incoming service requests (like for customer inquiry). The main server program finds an available socket and submits a new server job that performs specific functions for your request.

hrhsoleil692774: I have been doing sockets programming in RPG and VB for the past year and a half and am ready to move to SSL. I have two questions: 1. Have you experienced any problems using the SSL APIs in RPG? 2. What VB controls would you recommend for SSL?

Chris_Peters : Haven't really worked much with SSL (sorry) and am not really qualified to give you an opinion. Good hunting...

gurkha635749: What does "socket binding" mean?

Chris_Peters : "Binding" is the actual process of actually acquiring the logical socket resource used in communications.

deborah-mclellan114644 : Please tell me a little bit about sockets programming as it relates to RPG. Is RPG the back-end piece and Visual Basic the front-end piece?

Chris_Peters : Exactly. Using RPG as the server language on the 400 allows you to leverage your existing programming know-how, except with a very smart display station (the PC) running a capable client language like VB.

gurkha635749: Can more than one client connect to the same server port at the same time? Will the server serve the multiple clients?

Chris_Peters : No. You may specify that multiple incoming requests for processing be queued, but each process would be assigned it's own thread (or job).

jpthomas175851: Can I connect a sockets client to a port that was created by a socket server from a different application?

Chris_Peters : No. Normally, you use two sockets server program. A main server program that "listens" for incoming requests over a well-known socket. When a request is received, an available socket is found and a second server job is program is spawned (submitted.) The original connection to the main server program is ended, and the client is instructed to reconnect to the spawned server, under the assigned socket number. Typically, a production-quality c/s application will use a range of socket numbers, like 18201-18300. Port 18201 is the well-known port and 18202-18300 are for individual spawned jobs.

svenkatr65399: How do the sockets link one program to another?

Chris_Peters : Pretty much the same as a display file application. Sockets is the underlying communications support that allows two programs to pass data back and forth based on IP address and port number, much the same as a display file is controlled from a driver program through operating system support for interactive sessions. In sockets programming, you read and write to a sockets port, instead of a display file.

sscy782946: I use DoEvents within a Do....Loop waiting for a response. The Doevents allow further user interaction while the client app waits for a response. Is there another way to poll the winsock control other than using the DoEvents command?

Chris_Peters : No. You have to give the comm layer a time slice. The way I do it is to create a global integer that is incremented by the number of bytes received in the DataReceived event of the Winsock control. When the counter has the correct number of bytes, I process the incoming string. You still have to use DoEvents, though.

plumley544848: Are sockets strictly 'TCP' or can you use 'UDP'?

Chris_Peters : There are both (about 65000 of each.) When you establish your communications session, you tell TCP/IP support which "family" of protocols you'll be using -- TCP or UDP.

kim_hainam625802 : Instead of using the SUBMIT CL command to spawn a process on AS/400 can you use RPG to wrap C Function spawn()? If so, how?

Chris_Peters : Sure, but at present you cannot spawn an RPG program as a thread. The whole point of accessing sockets with RPG is to allow RPG programming skills to be used. Spawning the process would require development in C/400.

dwunder142903: Do you discuss "Sockets Programming " in your AS/400 Client/Server programming with Visual Basic 5.0?

Chris_Peters : No. That material is available as supplemental chapters, and is available from this event (documentation of sockets programming with RPG and code examples all in a zip file.)

Moderator: To get that zip file, Click on Tcp/Ip Documentation & Code (434KB).

plumley544848: Since 'sockets' programming is at the level of FTP or Telnet, do you have to assume all security concerns as the programmer?

Chris_Peters : Absolutely. Normally, you create the main server program with SECADM level of adopted authority. Then, when an incoming request for processing arrives, the main server program can use an IBM API to check the user's ID and password. If authorized, the spawned server program is submitted under the user's own profile, thus assuring normal access to resources. All of this is explained in detail in the documentation that you can download

svenkatr65399: What environment & languages do we use to do sockets programming?

Chris_Peters : The main thrust of this occasion is to place the server program on the AS/400, written in an ILE language like RPG. On the client side (PC,) a program is created to interact with the user and to perform communications with the server (just like a fancy display file program.) This client program is written in VB, C, Java, PowerBuilder, VA -- anything that can get at TCP/IP communications support using Windows APIs or a custom control. VB's the easiest.

berniebailey711484: Does the server establish the port number?

Chris_Peters : Yes. The server must be up and "listening" for an incoming connection request over a well-known port. (See prior answer regarding using a range of ports.)

sscy782946: Do you recommend programming the WinSock DLL directly over using the winsock.ocx control in VB?

Chris_Peters : Not unless you had some extraordinary requirement for reliability or security. For example, you wanted to send an acknowledgement of data received or establish a "checkpoint" mechanism for transmission restarts.

billg29705: On the VB side of things, what do you recommend as an interface to sockets? I've noticed that the WinSock API is fairly complex on the one extreme, but that the VB WinSock control is fairly limited on the other end. What I've looked for in the past is a COM DLL wrapper for WinSock functionality.

Chris_Peters : Your point is well taken, and typical of custom controls. In an effort to make them as simple to use as possible, they've lost much of their flexibility. Unfortunately, I know of no other solution -- you either have to get in there with the API or use a custom control to make the API calls for you. You could always write your own DLL to wrap the API.

jpthomas175851: When using the bound procedures supplied by IBM, is it possible to use either IP address or Host Name to determine the location of the socket server?

Chris_Peters : Yes. You can call an IBM API to convert from host name to IP address. The API will query the network for the IP address.

tdaly165639: How can I detect when a client has disconnected?

Chris_Peters : The main server program will receive a transmission from the client, but the transmission data will be zero bytes. The server program will recognize this as a disconnect request from the client and end gracefully.

svenkatr65399: How does the server do the session management for multiple simultaneous clients?

Chris_Peters : A range of 100 or so sockets are dedicated to the concurrent users. Each user is on a one-to-one conversation with an individual server program over a distinct port. As a port is no longer in use it goes back into the "pool" of ports within that range.

phinegeek611956: Is using the WinSock API quicker than using the ActiveX control?

Chris_Peters : Yes, slightly. But remember, the Winsock ActiveX control is only a wrapper for calls to the API, so you're accomplishing the same thing.

may621725: Are there any parameters that can be / should be adjusted on both ends (Client and Server) to optimize performance?

Chris_Peters : In sockets programming there are several. The main ones, though, are probably frame and data transport size. Frame size is the maximum number of bytes allowed on one packet and is determined by your network. Data transport size is up to you and should match the application. That is, if your dumping a lot of data to the client, make the transport size large, but if your just sending a short string make it smaller. (See the section in the downloadable documentation regarding performance factors.)

ronr881139: I may have missed something, but the participants might be interested in a free product called SocketsWrench made by Catalyst (www.catalyst.com). It is a sockets VB control and is very easy to use.

Moderator: ronr881139, thank you for your suggestion.

rbartels874498: Would a sockets server program be like a Java servlet running under WebSphere accessing your 400 data, but can be written in RPG?

Chris_Peters : Yes, but in sockets programming on the AS/400 you have to use the API calls, which are somewhat complex -- but doable.

gurkha635749: How does ILE RPG socket server compare with a Java sockets server on the AS/400 in terms of performance?

Chris_Peters : The same way that RPG and Java compare on the 400. Remember, you're still performing the same low-level communications tasks, regardless of the development language. The 400 is optimized for RPG, so the RPG program will run faster, given the same requirements.

rickm643172: When the socket server is running on the AS400, I see only one job. All clients are sending the request to the same port. The socket server job uses the giveDescriptor to send the request to a secondary socket server job based on the data received. The second socket server job uses the takeDescriptor and writes the results to the socket for the client to receive. Using this technique, how are multiple requests handled simultaneously? I always see only one job on the AS/400.

Chris_Peters : I suspect that the subsequent jobs are running as low-level processes (threads) within the main server program's process space. They aren't really new jobs, just new processes within the same job. I believe, however, that FTP will actually pre-spawn a new job on the 400.

chrisv2154630: I am attempting to replace the APPC ICF portion of our application that allows a small network of about 30 AS/400's to talk and exchange data via an interactive user interface. With sockets, are there any major "gotchas" I need to keep in mind?

Chris_Peters : There are a great many differences between sockets programming and APPC. Within sockets, a server program must be "listening" in advance for an incoming request. In APPC, the requestor can specify the name of the job that is to be started and used as the server, so you have to deal with it. I suggest you read the documentation available for download.

sscy782946: How do you recommend stopping a user from interacting with the program while the client waits for a previous response from the server, since DoEvents is required and DoEvents allows users to continue to interface with the program?

Chris_Peters : In our applications, we have to disable the controls that the user might press and then re-enable them when all of the data has been received.

xkong407723: Why not use Java in both server and client side?

Chris_Peters : These examples are done with RPG on the server side so that the customary users of the 400 (RPG programmers) can still use all of the programming skills they've acquired. Further, the 400 is optimized for RPG, and a server program written with RPG will run faster. The client side could be Java, sure.

Moderator: This concludes our Live Expert Q&A session with Chris Peters. For more information, you can check out Chris's books: AS/400 TCP/IP Handbook and AS/400 Client/Server Programming with Visual Basic 5.0.

Moderator: The following questions were answered after the conclusion this live event!

fyeung665383: In socket programming, how complicated is it to monitor the communication status and to perform data recovery?

Chris_Peters: It's certainly possible. (Witness the way that Telnet works -- if the host does not hear from a client within a given span of time, even if the client is at idle, the server will assume a communications problem has occurred and terminate the session.)

petet497994: Your book gives good examples when the AS/400 is the server and with a VB client -- what about a situation where I need to write a set of RPG client programs to talk with a PC server and do things like "heartbeat, disconnect/connect, eod/sod, convert to EBCDIC" etc. What would be the best way to get me started?

Chris_Peters: Please see the sockets programming documentation that was made available for download for this event. In there, there is an example of a client program written for the 400 in RPG called ENDMAINR. This example could be modified to meet your needs.

gurkha635749: When the client is instructed by the server to reconnect to the spawned server, does the client have to respond to the instruction explicitly and reconnect? Or is it done automatically under the covers?

Chris_Peters: Both sides must handle all of the disconnect/reconnect to a different port mechanism themselves.

svenkatr65399: Other than 'WinSock' what other ActiveX controls are commonly used in VB for Sockets Programming?

Chris_Peters: I know of none, but I haven't been looking lately. (You might try VBExtras for the latest controls.)

gurkha635749: What is the idle time the RPG socket server will allow before dropping the connection with a client if there is no activity? Can this time be changed? How?

Chris_Peters: You would set this value, and others, by setting the sockets options before the socket is bound (see SetSockOpt API documentation.)

hudson194414: On the RPG side, do you monitor requests through the listen function or the recv function?

Chris_Peters: Through the Listen function.

svenkatr65399: What are the main features of an ILE language like RPG? What other alternatives are there?

Chris_Peters: Any ILE programming language has the advantage of having the ability to interact with programs not written in the same language. In this case, the advantage is the ability to use AS/400 external functions that were previously only available to C/400 programmers.

svenkatr65399: What reference material would you suggest for a novice sockets programmer in VB?

Chris_Peters: Jeez, there's a ton of them. I suggest you get something like Internetworking with TCP/IP: Windows Sockets Version -- Client-Server Programming and Applications by Douglas E. Comer and David Stevens for the basics in TCP/IP sockets programming.

svenkatr65399: How does the server handle abnormal session terminations on the client side?

Chris_Peters: You have to provide the termination and recovery mechanisms in your programs.

tdaly165639: Follow up to Q310: What about the client ending abnormally? What happens is the client eventually reconnects, but the "child" job doesn't run because the still running first connection has some object locks. How can I tell if my client is still there?

Chris_Peters: You can set up a mechanism like Telnet uses -- if the host does not hear from a client within a given span of time, even if the client is at idle, the server will assume a communications problem has occurred and terminate the session.

tfollo628306: Not sure if this was submitted or not, but I would like to know why you shouldn't use ADO recordsets and work on that level and use the TCP/IP client server connections to have a client talk to a server.

Chris_Peters: See initial questions. ADO, ODBC, etc. are examples of the two-tier c/s design. Sockets programming gives you a three-tier design with the middle tier on the 400.

hudson194414: I have heard that the "Broken Pipe" error is a normal occurrence that needs to be programmed around. Is this true when using the SOCK_STREAM family?

Chris_Peters: Yes.

jpthomas175851: Can you give a good reference for the parameters for the IBM Sockets API's?

Chris_Peters: Use the documentation made available for download with this event.

may621725: You mentioned that server programming on the 400 side is somewhat tedious. Are there any third-party packages (similar to those on VB) that make creation of AS/400 servers easier?

Chris_Peters: Yes, I think there are a few -- some are even share-ware level. You might check around or search the forums.

sydnic950435: When a client connects to a socket, it is common to start to new thread for that client. How easy is it to use threads in RPG?

Chris_Peters: RPG is not thread-capable yet, so you have to start a new job instead.

miker256603: I have been trying to use the Fcntl() API, but have been unable to get my program to compile. Is there a known problem with this API? The error I receive is that the parameters are not defined; however, I defined them in the D specs of the program.

Chris_Peters: No, I haven't used it but I'll bet there is something wrong with your prototype definition if you're getting a compile error.

 
Go to upcoming iSeries 400 webcasts
Transcripts to Previous Webcasts
> Boost Domino Performance on your iSeries 400
Speaker: Kim Greene
> Sockets Programming with RPG & Visual Basic
Speaker: Chris Peters
> Telework Success Strategies for the Virtual Employee
Speaker: Joe Roitz
View our Webcast Library
By viewing webcasts in our library you are agreeing to receive relevant information from the sponsor.
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2010, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts