Sample code for 30+ languages & platforms
React Native

Revert a TLS Connection to Plain TCP

See more Socket/SSL/TLS Examples

Demonstrates Socket.ConvertFromSsl, which ends the TLS layer while leaving the underlying TCP connection open for subsequent unencrypted communication.

Background. This is the reverse of a STARTTLS-style upgrade and is valid only while TLS is currently active on the connection.

Chilkat React Native Downloads

React Native
import { 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;
  }

  // End the TLS layer while keeping the underlying TCP connection open for subsequent unencrypted
  // communication.  This is the reverse of a STARTTLS-style upgrade and is valid only while TLS is
  // active.
  try {
    await socket.convertFromSslAsync();
  } catch {
    console.log(socket.lastErrorText);
    return;
  }

  console.log('Reverted to a plain TCP connection.');
}