0

As this is my first question, so my apologies if I couldn't ask in a proper way.

I am implementing the server-client communication using lwip.

My server must be connected to multiple clients all the time.

For that I made my server listening on all its ports, and then when client wants to connect, the client will send the connect request and the server should accept it.

But the problem I am having is that the server keeps on waiting on lwip_accept() function for each client, which blocks the other clients connections also.

For example:

if there are 3 clients, who want to connect to server. Server is listening on its 3 ports for example. and now the lwip_accept() functions are being called like below:

client1Conn = lwip_accept(sock1, (struct sockaddr*)&client, (socklen_t*)&lenClient);
client2Conn = lwip_accept(sock2, (struct sockaddr*)&client, (socklen_t*)&lenClient);
client2Conn = lwip_accept(sock3, (struct sockaddr*)&client, (socklen_t*)&lenClient);

Now for some reason, if the client 1 is not present, then the server will not move further from the first lwip_accept call, as long as the client 1 becomes available, and till that time the other two clients who are available, will not be able to connect to server.

What I want is that the server checks for the client connection, and if the client is not available, then it should skip that and move to the next client connection.

What I tried is using lwip_fcntl like below

int flags = lwip_fcntl(sock1, F_GETFL, 0);
lwip_fcntl(sock1, F_SETFL, flags | O_NONBLOCK);
client1Conn = lwip_accept(sock1, (struct sockaddr*)&client, (socklen_t*)&lenClient);

But no effect, and lwip_ioctl like below

int nonblocking = 1;
lwip_ioctl(sock1, FIONBIO, &nonblocking);
client1Conn = lwip_accept(sock1, (struct sockaddr*)&client, (socklen_t*)&lenClient);

This makes the accept failed all the time.

I tried the solution given in How do I change a TCP socket to be non-blocking? but it didn't work either.

Is there any possible way to implement the required functionality?

Raza
  • 1

0 Answers0