Progress
External Program
Interfaces
Examples Using 4GL Sockets
The following sample procedures show a simple interaction between a socket server (
e-sktsv1.p
) and a socket client (e-sktcl1.p
). In this case, the socket server exits after handling a single connection and the socket client exits after receiving one data transmission from the server. These are event-driven examples, where the socket server only writes and the socket client only reads on their respective sockets:
The following sample procedures show how you can transfer a database record between a socket server (
e-sktsv2.p
) and a socket client (e-sktcl2.p
) using a raw transfer. It uses the sports database as the source (server) and a copy of the sports database as the target (client).This is a simple example in which the server waits for connections indefinitely (until you press the STOP key), but always sends the same database record to the client for each CONNECT event. Note how the server uses the RAW transfer to first copy the record from the database, then to specify the size of the MEMPTR memory from which the record is written on the socket. The server stores the size of the record as the first piece of information sent to the client, followed by the record:
In this example, the client (
e-sktcl2.p
) polls its socket procedurally until the data for the record is available to read. In this case, the client first waits for the size information, then waits for that number of bytes of customer data. It also uses this size information to set the size of the MEMPTR region for reading the record off the socket. Finally, note that the client deletes the socket object and frees MEMPTR memory after it disconnects from the server:
The following example also involves a client and server.
The server, e-sktsv3.p, demonstrates how to set qsize, the length of the pending-connection queue, while enabling the server-socket for connections.
The client, e-sktcl3.p (1 of 2), shows how to set and retrieve socket options.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |