I have TCP Socket server using react\socket.
Depending on received data from the client, it doing something, then it close connection with the client.
The problem is i can't understand how to make connection timeout, if the server have not received any data for a period of time, how to close connection?
I'm looking for same as i did with stream_socket_accept() using stream_set_timeout()
<?php
require __DIR__ . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$socket->listen(2222);
$socket->on('connection', function ($conn) {
$conn->on('data', function ($data) use ($conn) {
if (substr($data, 0, 3) == 'one') {
$conn->end('end_two');
}
else if (substr($data, 0, 3) == 'two') {
$conn->end('end_two');
}
else {
$conn->close();
}
});
});
$loop->run();
stream_set_timeout($client, 5);