Listening and responding to connection requests
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
After you enable a server socket for listening using the ENABLE-CONNECTIONS( ) method, AVM listens on the
specified port for client connections. When a socket client sends a connection
request to this port, AVM automatically accepts the connection.
When a connection is made on a server
socket the AVM creates a new socket for reading and writing to the socket. Also a
CONNECT event is fired and the AVM calls any event procedure or method that you have
specified using the SET-CALLBACK( ) function. The handle to the new read/write
socket is passed into the callback handler as an input parameter. In the callback
handler for the CONNECT event, the SELF system handle points to the server socket.
Note: In the
callback handler for the READ-RESPONSE event, the SELF system handle points to
the client socket.
To listen for connections on a server socket using the CONNECT event procedure:
- Define an internal procedure that takes one
INPUTparameter of typeHANDLEto serve as an event procedure. You can define this procedure in any procedure context that is active while listening for connections. - Specify the procedure you defined in Step 1 as a
CONNECTevent procedure by invoking theSET-CONNECT-PROCEDURE( )method on the server socket handle that you have enabled for listening. - Include input-blocking statements (such as
WAIT-FOR) orPROCESS EVENTSstatements in your code to handle events. When anyCONNECTevent is received in the context of one of these statements, the event procedure specified in Step 2 executes.
To listen for connection on a server socket using the CONNECT event method:
- Define a public method that takes one
INPUTparameter of typeHANDLEto serve as an event method. You can define this public method in any class that is active while the server is listening for connections. - Specify the method you defined in Step 1 as a
CONNECTevent method by invoking theSET-CALLBACK( )method on the server socket object that you have enabled for listening. - Include input-blocking statements (such as
WAIT-FOR) orPROCESS EVENTSstatements in your code to handle events. When aCONNECTevent is received in the context of one of these statements, the event method 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.