React Native
React Native
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
Chilkat React Native Downloads
import { Socket } from '@chilkat/react-native'
async function chilkatExample() {
const listenSock = new Socket();
try {
await listenSock.bindAndListenAsync(5000, 25);
} catch {
console.log(listenSock.lastErrorText);
return;
}
const connectedSock = new Socket();
try {
await listenSock.acceptNextAsync(20000, connectedSock);
} catch {
console.log(listenSock.lastErrorText);
return;
}
// Move the connection out of connectedSock and into a newly created member of this object's socket
// set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
// SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
const socketSet = new Socket();
try {
socketSet.takeSocket(connectedSock);
} catch {
console.log(socketSet.lastErrorText);
return;
}
console.log('Connection added to the socket set.');
}