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:
  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.

To listen for connection on a server socket using the CONNECT event method:

  1. Define a public method that takes one INPUT parameter of type HANDLE to serve as an event method. You can define this public method in any class that is active while the server is listening for connections.
  2. Specify the method you defined in Step 1 as a CONNECT event method by invoking the SET-CALLBACK( ) method on the server socket object 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 a CONNECT event 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.