How do I identify if the packet arrived by UDP or TCP protocol

I have virtual worlds which can be controlled by user through TCP and UDP (remotely via iPhone / Android phones).
How do I distinguish if the data arrived (from client’s point of view) via TCP / UDP protocol?


I’m assuming you are handeling the networking yourself, so you have full access to the conections themselves, however you are not handeling packets themselves. If you are handeling packets yourself, it would be quite usefull to know how you are doing your networking.

It’s relatively easy:
TCP uses handshaking and therefore sessions. To see if a packet is UDP or TCP, it has to be part of a TCP session. If a packet is part of a session, it must be TCP.
If the packet is UDP, it doesn’t have any session info. It doesn’t have to contain who sent it. It’s simply a single message.

I don’t know much about each protocol when it comes to packet setup, but a google search should give you more than enough information on that.

Hope this helps,