renato.semadeni Posted September 30, 2015 Share Posted September 30, 2015 Hi there, Is it right that the socket call "accept" is a blocking call? How could I interrupt it and get out of the lock? Kind regards, Renato Link to comment
ded Posted October 13, 2015 Share Posted October 13, 2015 Hello, you can call nonblock() on server socket after its creation. In that case, accept() will immediately return int value, which will tell you whether client is connected or not. Example: Socket server = new Socket(SOCKET_STREAM,8080); server.bind(); server.listen(10); server.nonblock(); thread([](Socket server) { Socket client = new Socket(SOCKET_STREAM); while(!server.accept(client)) { wait; } client.puts("Hello"); client.close(); server.close(); delete client; delete server; },server); Link to comment
Recommended Posts