SDL_net TCP and UDP

Hello

Here is a question that probebly does not belong in this group and I
appologize if that is the case.

I have been looking at SDL_net and the thing I don’t understand is what is
the difference between TCP and UDP. I know that udp is firewall unfriendly
for the most part. But I was actually looking for more of an architecture
answer. Also is it possible to create ip-to-ip connections using TCP instead
of UDP for a game with good results.

Thanks Ben
ps Also if possible could anybody let me know where I could find some docs
on TCP and UDP coding. Thanks

TCP makes sure the packets arrive at there destination (or at least
let’s you know if they don’t in a given amount of time), with UDP it’s
up to you to do that checking. Sometimes you don’t need to (like if
you are sending all the information needed to blit a sprite at any
given time it does’nt matter if some of the information does’nt get
through, when something finally does it will correct the display).
Any decent unix sockets reference should explain how to use either.
Everything I know about TCP and UDP came from o’reilly’s java network
programming book, but I would’nt recommend it for C/C++ programmers.

zander wrote:

Hello

Here is a question that probebly does not belong in this group and I
appologize if that is the case.

I have been looking at SDL_net and the thing I don’t understand is what is
the difference between TCP and UDP. I know that udp is firewall unfriendly
for the most part. But I was actually looking for more of an architecture
answer. Also is it possible to create ip-to-ip connections using TCP
instead> of UDP for a game with good results.

Thanks Ben
ps Also if possible could anybody let me know where I could find some docs
on TCP and UDP coding. Thanks

TCP makes sure the packets arrive at there destination (or at least
let’s you know if they don’t in a given amount of time), with UDP it’s
up to you to do that checking. Sometimes you don’t need to (like if
you are sending all the information needed to blit a sprite at any
given time it does’nt matter if some of the information does’nt get
through, when something finally does it will correct the display).
Any decent unix sockets reference should explain how to use either.
Everything I know about TCP and UDP came from o’reilly’s java network
programming book, but I would’nt recommend it for C/C++ programmers.

UDP lets you send lots of individual packets (of limited size) very
quickly. If you send them too quickly, some will get dropped, and they
might even arrive out of order. UDP is good for sending short status
updates (object positions in games, for instance), in cases where it
doesn’t matter too much if one update is lost. Different IP stacks
impose different limits on UDP packets.

TCP is a stream-based, byte-oriented protocol. It guarantees that
everything you send will come out correctly on the other end, in the
order you sent it. It might be a bit slower in some cases, but it’s
guaranteed to be reliable.

The best book on network programming I’ve found is Unix Network
Programming, by W. Richard Stevens. It’s a big hardcover book that goes
into socket programming with excruciating detail.

-John>

zander wrote:

Hello

Here is a question that probebly does not belong in this group and I
appologize if that is the case.

I have been looking at SDL_net and the thing I don’t understand is what is
the difference between TCP and UDP. I know that udp is firewall unfriendly
for the most part. But I was actually looking for more of an architecture
answer. Also is it possible to create ip-to-ip connections using TCP
instead
of UDP for a game with good results.

Thanks Ben
ps Also if possible could anybody let me know where I could find some docs
on TCP and UDP coding. Thanks

Just a summary for you,

With TCP/IP, you actually establish a connection between sender and
receiver. Each packet sent is ACK’d by the recipient - if the ack doesn’t
come back, TCP/IP automatically resends it for you. It provides
reliaibility at the expence of latency. This is why many games use UDP
rather than TCP/IP.

UDP is a bit different. Packets are sent but not acked. Depending on
network routing and other issues, they may not arrive… or may even
arrive but out of order.

UDP has much less latency because it doesn’t send/wait for acks/etc. But
you’ll probably have to build some sort of sequencing into it to handle
error conditions.

For example, say you send packets for a ship flying across the screen,
updating it’s position. If you move the ship in three steps and the
center step is lost, it doesn’t really matter - the third packet updates
them to the correct spot anyway. But if it were TCP/IP, the error
correction layer would have resent and added a delay that keeps the
client and server(or client) a bit more out of sync.

In such a situation, losing a packet isn’t a big deal - but it would be
important to make sure you get them in order. So you’d have to install
your own sequence error correcting. But you’d gain greatly in the latency
arena.

This latency issue is more important for continuously moving, high-speed
action based games, space ships flying across the screen… characters
jumping, running fast, etc. If you have something with granularized
slower paced actions TCP/IP may be sufficient.

As far as books on TCP/IP. I’d strongly suggest an O’Reilly book. I
believe the System V Programming book covers network programming. I’m not
sure if their “TCP/IP in a nutshell” book covers the programming side or
not, or just “systems networking”.–
Brian

Here is a question that probebly does not belong in this group and I
appologize if that is the case.

I have been looking at SDL_net and the thing I don’t understand is what is
the difference between TCP and UDP. I know that udp is firewall unfriendly
for the most part. But I was actually looking for more of an architecture
answer. Also is it possible to create ip-to-ip connections using TCP
instead
of UDP for a game with good results.

Thanks Ben
ps Also if possible could anybody let me know where I could find some docs
on TCP and UDP coding. Thanks

The best book on network programming I’ve found is Unix Network
Programming, by W. Richard Stevens. It’s a big hardcover book that goes
into socket programming with excruciating detail.

I second that recommendation. Steven’s books are not only as near an
authoritative reference you can come without reading the standards, they
are also quite easy to read. A definite must for any network programmer.

TCP ensure fairness of troughput and avoid nerwork to congestion.

Usually, game’s packets are small enough to avoid any trouble
of this kind, but beware of network congestion:

For routing reasons, beyond a given troughput, packets are automatcally lost.
That’s why TCP reduces his troughput if acks does not come back.
That’s why you should have some kind of acks anyways.
1% of packet lost is good, but if you reach 10% of packet lost
you should automatically reduce the troughput you uses.

Luc-Olvier

Hey, you guys are great, thanks for your help.

Later Ben