[C] select() won't stop responding to read from client

  • Thread starter Thread starter zeion
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on the issue of the select() function in a C server application continuously responding to a client due to not properly reading data from the file descriptor (fd). The user reports that select() returns the same client fd repeatedly, causing the server to spam responses. The solution involves ensuring that all available data is read from the fd, as select() indicates that data is present, not that it has been processed.

PREREQUISITES
  • Understanding of C programming language
  • Familiarity with socket programming concepts
  • Knowledge of the select() system call
  • Experience with file descriptors in Unix/Linux environments
NEXT STEPS
  • Research how to properly read data from a file descriptor in C
  • Learn about handling multiple clients using select() in socket programming
  • Explore the use of non-blocking sockets to manage client connections
  • Investigate the use of epoll as an alternative to select() for scalability
USEFUL FOR

Software developers, particularly those working on network applications in C, and anyone troubleshooting client-server communication issues using select().

zeion
Messages
455
Reaction score
1
Hi,

So I have written a server that will detect activity by connected clients using select. I am able to detect when a client has typed something from their keyboard, and then it will send send a message to the client in response.

The problem is that select() seems to be returning the same client fd in every iteration. So I would type one character from the client, then the server non-stop spams the client with the response message because it thinks that the client has still typed something.

How do I make it so that select() will only send the response message once and not forever?
I've already tried to remove client FD from the fd list and fflush but they don't do jack.
 
Technology news on Phys.org
Are you actually reading data from the fd, and all of it?

If not, then select is doing exactly what it's supposed to do: it's telling you there's data there to be read.
 

Similar threads

Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 3 ·
Replies
3
Views
13K
Replies
8
Views
4K
Replies
7
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
79
Views
10K
Replies
1
Views
4K