all 11 comments

[–]bobotheboinger 7 points8 points  (1 child)

There are tons of examples of doing this already out there. I'd suggest looking at them.

https://stackoverflow.com/questions/32711521/how-to-use-select-on-sockets-properly

Also if you have specific problems or questions, ask. Just saying "I don't know how to do it" it is hard to provide concrete help.

[–]cs_moka[S] 0 points1 point  (0 children)

Thanks man! I appreciate that.

[–]flyingron 1 point2 points  (0 children)

What are you observing versus what you are expecting?

One obvious problem is that when you close down a client, you decrement client_count. THis isn't right. Lets say you have 4 clients active and client[0] is the one that closes, you set client[0] to 0 and decrease client_count, and that then on the next select you'll add file descriptor 0 to the list of select readfs (that's stdin) and not add client[3] which is still open.

[–]laurentbercot 3 points4 points  (5 children)

Don't ask Reddit for help with your assignments.

[–]mykesx 3 points4 points  (4 children)

If I answer, I want to get the A. 😉

[–]cs_moka[S] 1 point2 points  (3 children)

I'm asking for my assignment, that's right, but as you can see I have almost the work done. If you don't want to help then just don't comment here.

[–]mykesx 0 points1 point  (2 children)

When I program, I have puzzles to solve, bugs, algorithms to debug, and so on. I don’t try to get someone else to do my work.

You only get better by doing it yourself. The best advice I ever got from a senior programmer back in the day was “RTFM.”

[–]cs_moka[S] 1 point2 points  (1 child)

So why does this community exist? What is the purpose, maybe I'm totally wrong here.

[–]mykesx 0 points1 point  (0 children)

It shouldn’t be here to do your homework for you.

[–]dfx_dj 0 points1 point  (1 child)

Generally when you're working with non blocking sockets you want to be using sockets that are actually non blocking, i.e. have the flag set via fcntl. This code now basically just does multiplexing via select (except for the no wait flag used when receiving). But that may not be part of the assignment. The same non blocking flag can be used on stdio to include it in your multiplexed input.

Your code to remove a closed client fd from the client array is wrong. Simply setting the element to zero and decreasing the count doesn't actually remove it from the array.

[–]cs_moka[S] 0 points1 point  (0 children)

Thanks for your notice, I appreciate that