Sample code for 30+ languages & platforms
React Native

Receive Bytes up to a Delimiter into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.

Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.

Chilkat React Native Downloads

React Native
import { BinData, Socket } from '@chilkat/react-native'

async function chilkatExample() {
  const socket = new Socket();

  // Connect to the server using TLS.
  const bTls = true;
  const maxWaitMs = 5000;
  try {
    await socket.connectAsync('example.com', 5000, bTls, maxWaitMs);
  } catch {
    console.log(socket.lastErrorText);
    return;
  }

  // Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
  // delimiter to a BinData.  The delimiter is a raw byte value from 0 through 255 (here the linefeed
  // byte, decimal 10).
  const bd = new BinData();
  try {
    await socket.receiveUntilByteBdAsync(10, bd);
  } catch {
    console.log(socket.lastErrorText);
    return;
  }

  console.log(`Received ${bd.numBytes} bytes (including the delimiter).`);
}