listenAsynch

listenAsynch(receiver: Object;
             msg:      String);

The listenAsynch method of the TcpIpConnection class waits for a remote application to connect to its port and returns immediately.

When a connection attempt has been made by a remote application, the object specified in the receiver parameter is sent the message specified in the msg parameter.

The listenAsynch method can be called only when the value of the Connection class state property is Disconnected (0).

When this method is called, the value of the state property changes to Connecting (1). See also the Connection class timeout property.

On asynchronous calls, the state may not change immediately and it may remain Disconnected (0) for a short period until JADE has rescheduled the request.

The following example of the listenAsynch method sets the authentication challenge and verification methods for the connection.

listenAsynch_click(btn: Button input) updating;
vars
    conlog : ConnectionLog;
begin
    self.tcp.genAuthChallengeMethod   := "okGenAuthChallenge";
    self.tcp.verifyAuthResponseMethod := "okVerifyAuthResponse";
    // Sets the conlog variable to reference a ConnectionLog object.
    // If none exists, the object is created and its properties
    // are initialized.
    conlog := ConnectionLog.firstInstance;
    if conlog = null then
        beginTransaction;
            create conlog;
            conlog.numberOfListenCalls  := 0;
            conlog.numberOfOpenCalls    := 0;
            conlog.numberOfCloseCalls   := 0;
            conlog.numberOfBinaryReads  := 0;
            conlog.numberOfBinaryWrites := 0;
        commitTransaction;
    endif;
    // Sets the tcp to listen on the current port and returns
    // immediately.  If a connection is made, the ConnectionLog object
    // referenced by conlog is called and told to run the updateListenCalls
    // method.
    self.tcp.port := 7895;
    self.tcp.listenAsynch(conlog, "updateListenCalls");
end;

The user-written callback method specified in the msg parameter is called when the listenAsynch method receives a connection request. The callback method must match the signature required by the listenAsynch method, as follows.

listenCallback(tcp: TcpIpConnection);

The following method is an example of a ConnectionLog class callback method for the listenAsynch method, which updates the number of method invocations recorded for this method.

updateListenCalls(tcp: TcpIpConnection) updating;
begin
    beginTransaction;
    self.numberOfListenCalls := self.numberOfListenCalls + 1;
    commitTransaction;
end;