readBinaryAsynch(length: Integer; receiver: Object; msg: String);
The readBinaryAsynch method of the Connection 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 fillReadBuffer property, the object specified in the receiver parameter is sent the name of the callback method 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 state property is Connected (2).
The following example shows the use of the readBinaryAsynch method.
receiveAsynch_click(btn: Button input) updating; vars conlog : ConnectionLog; begin // Sets the variable conlog to reference a ConnectionLog object. If // none exists, the object is created and its properties initialized. if self.connection.state = Connection.Connected then beginTransaction; conlog := ConnectionLog.firstInstance; if conlog = null then create conlog; conlog.numberOfListenCalls := 0; conlog.numberOfOpenCalls := 0; conlog.numberOfBinaryReads := 0; conlog.numberOfBinaryWrites := 0; endif; commitTransaction; // 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.connection.readBinaryAsynch(50, conlog, "updateBinaryReads"); endif; end;
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 callback method must match the signature required by the calling readBinaryAsynch method, as follows.
readBinaryCallback(connection: Connection; buffer: Binary);
The following is an example of a ConnectionLog class callback method for the readBinaryAsynch method, which updates the number of method invocations recorded for this method.
updateBinaryReads(connection: Connection; buffer: Binary) updating; begin beginTransaction; self.numberOfBinaryReads := self.numberOfBinaryReads + 1; commitTransaction; end;
See also the Connection class timeout property.