I have a problem about select function when I worked on a Linux socket program. The select function worked fine as the man page says if the client connected the server side
You have the right answer already - re-init the fd_sets before each call to select(2).
I would like to point you to a better alternative - Linux provides epoll(4) facility. While it's not standard, it's much more convenient since you need to setup the events you wait for only once. The kernel manages the file descriptor event tables for you, so it's much more efficient. epoll also provides edge-triggered functionality, where only a change in state on a descriptor is signaled.
For completeness - BSDs provide kqueue(2), Solaris has /dev/poll.
One more thing: your code has a well known race condition between a client and the server. Take a look at Stevens UnP: Nonblocking accept.