Thanks for the posts above. So if I change the second listen to accept, that should do work?
If the accept works well, do I still need to explictly close the socket, or the socket will be closed automatically?
How do I see monitor the sockets opened? I was using netstat -na |grep port#, but feel it is not very effective.