TcpServer.classPrototype.bind
- Instance of
- Parameters
-
port /*Number*/
- Return value
-
this
Description
Assigns socket to port and start listening for client connections.
Example
let tcpServer = TcpServer();
let port = 3000;
let portNotSet = true;
while (portNotSet) {
try {
await tcpServer.bind(port++);
portNotSet = false;
} catch {
// https://wiki.c2.com/?PokemonExceptionHandling
}
}
tcpServer.listen().then((tcpClientB) => {
console.write(await tcpClientB.receive());
await tcpClientB.close();
});
let tcpClientA = TcpClient();
await tcpClientA.connect("127.0.0.1", port);
await tcpClientA.send("abcd");
await tcpClientA.close();
Expected output
abcd