React Native
React Native
Upgrade a Plain TCP Connection to TLS
See more Socket/SSL/TLS Examples
Demonstrates Socket.ConvertToSsl, which upgrades an already-connected plain TCP socket to TLS by performing a client-side TLS handshake over the existing connection.
Background. This supports STARTTLS-style upgrades, where a protocol begins in plaintext and switches to TLS at a defined point. Perform the protocol-specific negotiation first, then call ConvertToSsl.
Chilkat React Native Downloads
import { Socket } from '@chilkat/react-native'
async function chilkatExample() {
const socket = new Socket();
// Connect as plain TCP (no TLS yet).
const bTls = false;
const maxWaitMs = 5000;
try {
await socket.connectAsync('example.com', 5000, bTls, maxWaitMs);
} catch {
console.log(socket.lastErrorText);
return;
}
// At the point where the application protocol permits a STARTTLS-style upgrade, perform any required
// negotiation, then upgrade the existing connection to TLS with a client-side handshake.
try {
await socket.convertToSslAsync();
} catch {
console.log(socket.lastErrorText);
return;
}
console.log('Connection upgraded to TLS.');
}