openAsynch

openAsynch(receiver: Object;
           msg:      String);

The openAsynch method of the TcpIpConnection class establishes a connection to a remote application and returns immediately. When the connection is established, the object specified in the receiver parameter is sent the message specified in the msg parameter.

Use the name property of the Connection class to define the name or the IP address of the TCP/IP target host used when opening a TCP/IP connection using the open or openAsynch method. The name property, if not an IP address, must be specified in the local HOSTS file or be defined on the Domain Name Service (DNS) node before executing the open or openAsynch method.

Use the port property to define the target service port when using the open or openAsynch method or to define the listen port when using the listen or listenAsynch method.

The openAsynch 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).

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 openAsynch method sets the authentication response for the connection.

buttonOpenAsynch_click(btn: Button input) updating;
vars
    conlog : ConnectionLog;
begin
    self.tcp.genAuthResponseMethod := "okGenAuthResponse";
    // Attempts to connect to the current port and returns immediately.
    // If a connection is made, the ConnectionLog object referenced by
    // conlog is called and told to run the updateOpenCalls method.
    self.tcp.openAsynch(conlog, "updateOpenCalls");
end;

When the openAsynch method establishes a connection, the user-written callback method specified in the msg parameter is called. The callback method must match the signature required by the calling openAsynch method, as follows.

openCallback(tcp: TcpIpConnection);

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

updateOpenCalls(tcp: TcpIpConnection) updating;
begin
    beginTransaction;
    self.numberOfOpenCalls := self.numberOfOpenCalls + 1;
    commitTransaction;
    self.tcp.readBinaryAsynch(1024, tcp, "readCallback");
end;