Sample code for 30+ languages & platforms
React Native

Send Bytes on a Socket Connection

See more Socket/SSL/TLS Examples

Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.

Chilkat React Native Downloads

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

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const socket = new Socket();

  // Connect to some host:port
  const ssl = false;
  const maxWaitMillisec = 20000;
  const port = 5555;
  try {
    await socket.connectAsync('test.com', port, ssl, maxWaitMillisec);
  } catch {
    console.log(socket.lastErrorText);
    return;
  }

  // We wish to send a 0x00 byte followed by the us-ascii string "10800"
  const bd = new BinData();

  bd.appendByte(0);
  bd.appendString('10800', 'utf-8');

  // Send the entire contents of bd.
  try {
    await socket.sendBdAsync(bd, 0, 0);
  } catch {
    console.log(socket.lastErrorText);
    return;
  }
}