readBinaryAsynch

readBinaryAsynch(length:   Integer;
                 receiver: Object;
                 msg:      String);

The readBinaryAsynch method of the TcpIpConnection class reads binary data from the connection and returns immediately. When the bytes of data specified in the length parameter have been read or when a block of data is received, depending on the setting of the Connection class fillReadBuffer property, the object specified in the receiver parameter is sent the message specified in the msg parameter.

Only one synchronous or asynchronous read operation can be performed at one time on a connection.

The readBinaryAsynch method can be called only when the value of the Connection class state property is Connected (2). See also the Connection class timeout property.

When the bytes of data specified in the length parameter have been read or when a block of data is received, the user-written callback method specified in the msg parameter is called. The value of the length parameter must be greater than zero (0).

The following example of the readBinaryAsynch method sets the decryption method for the connection.

receiveAsynch_click(btn: Button input) updating;
vars
    conlog : ConnectionLog;
begin
    self.tcp.decryptMethod := "okDecrypt";
    // Sets the conlog variable to reference a ConnectionLog object.
    // If none exists, it is created and its properties initialized.
    if self.tcp.state = Connection.Connected then
    // Reads binary data from the connection and returns immediately.
    // When the data is read, the ConnectionLog object referenced by
    // conlog is called and told to run the updateBinaryReads method.
    // It is passed a parameter containing the binary data that was
    // read from the connection.
       self.tcp.readBinaryAsynch(50, conlog, "updateBinaryReads");
    endif;
end;

The callback method must match the signature required by the calling readBinaryAsynch method, as follows.

readBinaryCallback(tcp:    TcpIpConnection;
                   buffer: Binary);

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

updateBinaryReads(tcp:    TcpIpConnection;
                  buffer: Binary) updating;
begin
    beginTransaction;
    self.obj.data := buffer;
    commitTransaction;
    self.tcp.readBinaryAsynch(1024, self.tcp, "readCallback");
end;