React Native
React Native
Accept the Next Incoming Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.AcceptNext, which waits for and accepts the next incoming connection on a listening socket, delivering it as a new connected Socket.
Background. A maxWaitMs of 0 waits indefinitely; a positive value waits up to that many milliseconds. For a TLS listener, acceptance includes the server-side TLS handshake.
Chilkat React Native Downloads
import { Socket } from '@chilkat/react-native'
async function chilkatExample() {
const socket = new Socket();
try {
await socket.bindAndListenAsync(5000, 25);
} catch {
console.log(socket.lastErrorText);
return;
}
// Wait for and accept the next incoming connection on the listening socket. maxWaitMs = 0 waits
// indefinitely; a positive value waits up to that many milliseconds. For a TLS listener, acceptance
// includes the server-side TLS handshake.
const connectedSock = new Socket();
try {
await socket.acceptNextAsync(20000, connectedSock);
} catch {
console.log(socket.lastErrorText);
return;
}
console.log(`Accepted a connection from ${connectedSock.remoteIpAddress}`);
}