readBinary

readBinary(length: Integer): Binary;

The readBinary method of the TcpIpConnection class reads binary data from the connection and returns when the number of 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.

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

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

When executing the readBinary notification method, ensure that all received data has been handled, copied, or stored before issuing another readBinaryAsynch method.

If the readBinary notification method executes another readBinaryAsynch method, it overwrites the data that was previously received if data is readily available on the connection.

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

buttonReceive_click(btn: Button input) updating;
begin
    self.tcp.decryptMethod := "okDecrypt";
    // Checks to make sure TCP is in connected state (2).  If it is
    // and binary data is received through the connection, displays
    // the data in the text box.  The parameter of 50 specifies that
    // the data must be no more than 50 bytes long.
    if self.tcp.state = Connection.Connected then
        textBox1.text := self.tcp.readBinary(50).String;
    endif;
end;

See also the readBinaryAsynch method.