Correct me if my anser seems as if I misunderstood your question. I also read Beej's guide, and went on to do a lot of windows socket programming. I remember a little bit about that example at the end. The server MUST. If the server doesn't loop, then it will not answer any sockets that enter it's que. One thing you can do though is to put the server loop in it's own thread, that way the program doesn't seem as if it's hanging. As far as the client goes, you kida-sorta have to wait. If the server is busy and takes a few milliseconds over average to respond, the client will drop if no waiting action is implemented. The reason that waiting is implemented is for 2 reasons: (1) as far as the server goes, it doesn't know when connections are going to come in, so it doesn't know when to check. Solution: check it all the time! thus the looping; (2) when a client makes a request, the server WILL NOT respond that instant, so you need to implement SOMETHING that will allow the server a few milliseconds (or if it's really lagging, start counting in seconds) of time to do it's processing and respond. I hope this helped.
|