listenContinuousAsynch

listenContinuousAsynch(receiver: Object;
                       msg:      String);

The listenContinuousAsynch method of the Connection class waits for remote applications 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 name of the callback method specified in the msg parameter.

The listenContinuousAsynch method can be called only when the Connection class state is Disconnected (0). When this method is called, the value of the state property is changed to Connecting (1).

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 shows the use of the listenContinuousAsynch method.

listenContAsynch_click(btn: Button input) updating;
vars
    conlog : ConnectionLog;
begin
    // Sets the conlog variable to reference a ConnectionLog object.
    // If none exists, it is created and its properties initialized.
    beginTransaction;
        conlog := ConnectionLog.firstInstance;
        if conlog = null then
            create conlog;
            conlog.numberOfListenCalls  := 0;
            conlog.numberOfOpenCalls    := 0;
            conlog.numberOfCloseCalls   := 0;
            conlog.numberOfBinaryReads  := 0;
            conlog.numberOfBinaryWrites := 0;
        endif;
    commitTransaction;
    // Sets the connection to listen on the current port.  A new instance
    // of Connection is created when a connection is made.  The original
    // instance remains available for listening on subsequent calls while
    // the new instance maintains the newly made connection.  When this
    // connection is made, the ConnectionLog object referenced by conlog is
    // called and told to run the updateListenContinuousCalls method.  The
    // new Connection instance is passed to this method as a parameter.
    self.connection.listenContinuousAsynch(conlog,
                                           "updateListenContinuousCalls");
    if self.connection.state = Connection.Connected then
        statusLine1.caption := "Connected";
        textBox.text        := self.connection2.name;
    endif;
end;

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

listenContinuousCallback(listener:      Connection;
                         newConnection: Connection);

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

updateListenContinuousCalls(connection:    Connection;
                            newConnection: Connection) updating;
begin
    beginTransaction;
    self.numberOfListenContinuousCalls := self.numberOfListenContinuousCalls
                  + 1;
    commitTransaction;
    self.newConnection.readBinaryAsynch(1024, newConnection,
                                        "readCallback");
end;

The listenContinuousAsynch method continues accepting new connection requests until the listener Connection class instance is closed.

The listenContinuousCallback method is called for every successful connection request.

See also the Connection class timeout property.