Thread: Do online games use TCP or UDP

Results 1 to 6 of 6
  1. #1 Do online games use TCP or UDP 
    Registered Member
    Join Date
    Sep 2012
    Posts
    119
    Thanks given
    76
    Thanks received
    11
    Rep Power
    36
    I'm currently trying to understand the concept of online multiplayer of a game (in this case I'm making a simple online ping pong game) and I'm wondering whether it is best to use tcp or udp to handle packets. I have knowledge of using TCP e.g. ServerSocket to create a multi user chat server, but I'm still learning how to code UDP (DatagramSocket). Now I'm asking is it better to use UDP for online games or TCP? I appreciate any advice anyone gives me Thanks!
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Jul 2013
    Posts
    119
    Thanks given
    12
    Thanks received
    50
    Rep Power
    83
    This is extremely broad, and it depends on your game and networking knowledge.

    UDP has the downside of manual packet management, as they will not arrive in the order they were sent (if they arrive at all, UDP is unreliable). However, you can be certain that when you send data, it sends right away, as there's no buffering that takes place.

    With TCP, you don't have to worry about packet ordering, so no need to write your own system to handle it. On the downside, TCP uses a buffering system, since it's a stream based protocol. IF you were to attempt to send a small packet, it may get held up in the buffer until there's enough data worth sending.

    As you can see, it depends. For high-speed games, such as first person shooters where potentially small packets are constantly sent, you'd want to stick with UDP to avoid any buffer issues. Otherwise, TCP will save you a lot of leg work.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Sep 2012
    Posts
    119
    Thanks given
    76
    Thanks received
    11
    Rep Power
    36
    Quote Originally Posted by ipwxy View Post
    This is extremely broad, and it depends on your game and networking knowledge.

    UDP has the downside of manual packet management, as they will not arrive in the order they were sent (if they arrive at all, UDP is unreliable). However, you can be certain that when you send data, it sends right away, as there's no buffering that takes place.

    With TCP, you don't have to worry about packet ordering, so no need to write your own system to handle it. On the downside, TCP uses a buffering system, since it's a stream based protocol. IF you were to attempt to send a small packet, it may get held up in the buffer until there's enough data worth sending.

    As you can see, it depends. For high-speed games, such as first person shooters where potentially small packets are constantly sent, you'd want to stick with UDP to avoid any buffer issues. Otherwise, TCP will save you a lot of leg work.
    So with TCP basically its not essential to use in games where movement is involved (like moving a character from one position to another), but more for like communicating between others or like sending a file to another client connected within the same server because those things MUST be delivered. But UDP you should use it to send a packet when a player has moved and it sends it fast enough that it may or may not be lost a long the way.
    Reply With Quote  
     

  4. #4  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,871
    Thanks given
    1,854
    Thanks received
    4,745
    Rep Power
    5000
    Quote Originally Posted by Rondo View Post
    So with TCP basically its not essential to use in games where movement is involved (like moving a character from one position to another), but more for like communicating between others or like sending a file to another client connected within the same server because those things MUST be delivered. But UDP you should use it to send a packet when a player has moved and it sends it fast enough that it may or may not be lost a long the way.
    Yes, most games may use both and use protocols depending on the importance of the data. TCP for chat and any other essential stuff that you expect to get delivered, UDP when you can afford some loss such as fast paced movement where the server is doing lots of prediction anyway

    Attached image

    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Registered Member

    Join Date
    Jul 2013
    Posts
    119
    Thanks given
    12
    Thanks received
    50
    Rep Power
    83
    Quote Originally Posted by Rondo View Post
    So with TCP basically its not essential to use in games where movement is involved (like moving a character from one position to another), but more for like communicating between others or like sending a file to another client connected within the same server because those things MUST be delivered. But UDP you should use it to send a packet when a player has moved and it sends it fast enough that it may or may not be lost a long the way.
    Both have their pros and cons. Of course TCP isn't essential, it's just handy when it comes to sending data reliably.

    If data goes missing, TCP will retransmit the data. This is the key concept of TCP.
    When the TCP transmits a segment containing data, it puts a copy on a retransmission queue and starts a timer; when the acknowledgment for that data is received, the segment is deleted from the queue. If the acknowledgment is not received before the timer runs out, the segment is retransmitted.
    RFC 793

    UDP doesn't follow this same concept. The idea for UDP is to avoiding waiting by removing the need for a retransmission queue. This means data might be lost, but in the right enviornment, that's just fine.

    Example

    Imagine you're playing Call of Duty.

    It's important to send information anytime change occurs between clients. The angle difference the player's camera, the difference in location, etc.. Anything that may affect the player's gameplay must be logged to ensure top notch performance. That's a lot of data.

    This means it's not wise to wait for data, as there's quite a bit of data that needs to be transmitted. So you must be wondering about the missing packets: how can programs run properly when packets go missing?

    Keep in mind how fast these packets are being sent over. If one goes missing here or there, it's fine, as there's another slightly different (but not too much different) one coming along the way.

    As for that small timeframe of missing, dead reckoning covers it by simply reusing the last frame of data. It continues using that data until a new update packet is sent. In UDP, packets aren't lost as often as you think (maybe around 1-2%), so as long as your network logic is sound, you won't even notice.

    But dead reckoning can't be applied in all situations. If your game isn't constantly sending data over, then you'll want reliable data. As S Quare Quxx mentioned, you may find yourself using both: UDP for game world, TCP for chat, or something along those lines.
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Sep 2012
    Posts
    119
    Thanks given
    76
    Thanks received
    11
    Rep Power
    36
    Quote Originally Posted by ipwxy View Post
    Both have their pros and cons. Of course TCP isn't essential, it's just handy when it comes to sending data reliably.

    If data goes missing, TCP will retransmit the data. This is the key concept of TCP.
    RFC 793

    UDP doesn't follow this same concept. The idea for UDP is to avoiding waiting by removing the need for a retransmission queue. This means data might be lost, but in the right enviornment, that's just fine.

    Example

    Imagine you're playing Call of Duty.

    It's important to send information anytime change occurs between clients. The angle difference the player's camera, the difference in location, etc.. Anything that may affect the player's gameplay must be logged to ensure top notch performance. That's a lot of data.

    This means it's not wise to wait for data, as there's quite a bit of data that needs to be transmitted. So you must be wondering about the missing packets: how can programs run properly when packets go missing?

    Keep in mind how fast these packets are being sent over. If one goes missing here or there, it's fine, as there's another slightly different (but not too much different) one coming along the way.

    As for that small timeframe of missing, dead reckoning covers it by simply reusing the last frame of data. It continues using that data until a new update packet is sent. In UDP, packets aren't lost as often as you think (maybe around 1-2%), so as long as your network logic is sound, you won't even notice.

    But dead reckoning can't be applied in all situations. If your game isn't constantly sending data over, then you'll want reliable data. As S Quare Quxx mentioned, you may find yourself using both: UDP for game world, TCP for chat, or something along those lines.
    Quote Originally Posted by S Quare Quxx View Post
    Yes, most games may use both and use protocols depending on the importance of the data. TCP for chat and any other essential stuff that you expect to get delivered, UDP when you can afford some loss such as fast paced movement where the server is doing lots of prediction anyway
    Thank you both of you for taking time in giving me some advice on how this works! Now I got some learning to do.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. What is the biggest fail online game
    By DJ Cheetos in forum PC
    Replies: 163
    Last Post: 12-02-2009, 11:00 PM
  2. Replies: 4
    Last Post: 07-15-2008, 08:48 PM
  3. Best Online game?
    By Arvid in forum Voting
    Replies: 15
    Last Post: 04-18-2008, 02:46 AM
  4. do you then im nice or mean?
    By yankee in forum Voting
    Replies: 3
    Last Post: 04-06-2008, 08:32 PM
  5. rate these (i dont use photoshop or gimp)
    By Scaar in forum Showcase
    Replies: 7
    Last Post: 05-16-2007, 04:56 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •