React Native
React Native
Duplicate a Socket Wrapper Sharing the Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.
Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.
Chilkat React Native Downloads
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;
}
// Create a second Socket wrapper that shares this object's underlying connection. Both wrappers
// operate on the same live connection; the shared connection is reference-counted.
const dupSock = new Socket();
try {
socket.dupSocket(dupSock);
} catch {
console.log(socket.lastErrorText);
return;
}
console.log('Duplicate socket wrapper created.');
}