Advertisement

listening

Started by April 08, 2004 05:35 PM
2 comments, last by Funkymunky 20 years, 10 months ago
Hey I''ve been reading Beej''s and looking around for TCP/IP stuff and have a couple more questions (hope ya dont mind!) First off, if I want to get connected to, do I have to be constantly listening in a loop until I get the connect call? Or is there a way I can just send information across the network and have the other computer start listening/connecting once it gets the signal? If not, is listening a serious detriment to the computers performance / the network? Also, whats this UDP vs TCP stuff? I heard UDP is better for time critical stuff, but do you still use all the same send listen connect etc. calls?
Basically, you got it. The server should just constantly listen for incoming connections in a loop. Once a connection is established, create a new thread that hadles the communication with it from there on. That leaves the original thread free to listen for the next connection and so on. This is how many client-server systems work.
Advertisement
UDP is good for time sensitive data, but only where data loss is acceptable. This is because it does not provide error checking. The classic example is streaming audio and video -- no one''s complaining too much if there are anomalies here and there, so long as the information pipes in fast enough to not cause stutters and pauses (particularly bad for webcasting), its OK. This is generally NOT the case for transmitting game data. Just use TCP.
---------------------------Brian Lacy"I create. Therefore I am."
You can use select() to check for an incoming connection request on a listening socket.
Matt Slot / Bitwise Operator / Ambrosia Software, Inc.

This topic is closed to new replies.

Advertisement