Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : Sockets : Implementing an ABL socket server : Listening and responding to connection requests
Listening and responding to connection requests
After you enable a server socket for listening using the ENABLE-CONNECTIONS( ) method, ABL listens on the specified port for client connections. When a socket client sends a connection request to this port, ABL automatically accepts the connection.
After accepting the connection, ABL posts a CONNECT event on the server socket and calls the CONNECT event procedure that you have specified using the SET-CONNECT-PROCEDURE( ) method. The CONNECT event procedure executes, returning a handle to a socket object created by ABL and passed as a parameter to the event procedure context. This socket object, then, is the communications endpoint for the connection on the server.
To listen for connections on a server socket using the CONNECT event procedure:
1. Define an internal procedure that takes one INPUT parameter of type HANDLE to serve as an event procedure. You can define this procedure in any procedure context that is active while listening for connections.
2. Specify the procedure you defined in Step 1 as a CONNECT event procedure by invoking the SET-CONNECT-PROCEDURE( ) method on the server socket handle that you have enabled for listening.
3. Include input-blocking statements (such as WAIT-FOR) or PROCESS EVENTS statements in your code to handle events. When any CONNECT event is received in the context of one of these statements, the event procedure specified in Step 2 executes.
Once you have the handle to a connected socket object, you can read and write data on the socket, and otherwise manage the socket for the connection. For more information, see Read, writing, and managing sockets on clients and servers.