OO Socket Sample Code

Using sockets with the 4gl and classes is an "interesting" exercise. This book contains examples of how to use classes and sockets for a client and server system. There are examples of how to use the client to connect to a web page and download the source. There is also a client / server system that uses XML to pass messages between the server and clients.

General Principles

There are two types of socket, a server socket and a client socket. The server socket spawns a client socket when a client connects. Each client socket is managed by the ClientSocket class. So, when a client connects to the server, the server creates a client connection socket.

Each socket has it's own read-response handler in the form of a persistent procedure.

Each socket has a message "terminator", so that a block of data can be sent en masse. Normally, this terminator is set to "~n", so each line of text will be published as a new message.


Every time a complete message is received, the message is published as "MessageIn". By default, MessageIn resides in the .w or .p that created the socket class. The following parameters are passed to MessageIn:

Socket: The handle of the socket that received the message
Message Type: The type of message (user defined)
Message From: The name of the client that sent the message
Message To: The name of the client the message was sent to
Message Subject: The subject of the message
Message Body: The body of the message

By default, the complete message is always in the Message body. If the client and server are using XML, then all parameters will be filled appropriately.


To connect a client to a server, the Connect() method should be used. There are several overrides to the Connect method:

Connect(): Connect to the host and port specified in the Host and Port properties
Connect(Port): connect to the host specified by the Host Property and the supplied Port parameter
Connect(Host,Port): connect to the supplied host and supplied Port parameters

Samples / Examples

There are the following examples supplied:


Uses a client socket to connect to a web page


Shows how you can implement a 4GL-based XML messaging system that can be used to PUB/SUB across session boundaries


Unzip the dotr.com.zip file into a directory in the propath. You must keep the com\dotr directory structure.

The latest source code can be checked out from svn://oehive.org/oosockets/trunk


All comments are welcome and appreciated.


All the code supplied here is licensed under the BSD license. You are free to copy and use the code as you see fit. However, I would welcome any code changes so that I can make this a better example for all OE users. Thanks !

dotr.com_.zip39.91 KB


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jurjen's picture

latest version of oosockets

Please notice there is a much newer version available at http://communities.progress.com/pcom/message/82703

That newer version is unfortunately not (yet) checked in into the subversion repository at http://websvn.oehive.org/listing.php?repname=oosockets