Solved

Network protocol for Games

Posted on 2003-12-02
7
1,735 Views
Last Modified: 2013-12-04
I'm eventually interested in programming a small netcode for a massively multyplayer game (FPS).
I need to know some basics on the protocoll development for games:
Which protocol (UDP / TCP)?
Anything special for speeding up the communication.

Also I would like to know how to send the data across the net... (sending raw structs read from memory, or some higher data encapsulation such as plaintext).
0
Comment
Question by:Snyke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 50 total points
ID: 9863589
(1) How games send data across the wire varies, game to game. UDP is cheaper than TCP since packets don't have to be buffered and delivered in order: less overhead in the packets used (compared to payload) and less latency in getting information to the distant process. Disadvantage is no delivery guarantees.

(2) Speeding up the connection: The fastest packet is the one you don't send so send as little as you can get away with. What is the range:
(a) Client/Server model where all input is sent from client to server, all calculations done on the server, and all data for output returned to the client for rendering.
    Lots of data probably comes back down; scalability problems but every client has the exact same picture of the game.
(b) Peer/Peer model where only input signals are replicated, machine to machine, and each runs the full game with all calculations done locally.
   Lots less data; scales well; clients are more losely coupled AND can be used for cheating.

(3) Data across the net: You can send raw  data using pointers at structs/classes IF you know that all machines will be using the same processor (don't include Mac and PC versions of your code) and you can afford to send the whole struct every time a single field changes. Alternative is to send some sort of tag (indicating the object and the field) and then ONLY the changed value. Only makes sense if the tags are smaller than the remainder of the object.

Just some thoughts. Hope it helps, -bcl
0
 
LVL 1

Author Comment

by:Snyke
ID: 9866643
Is there a possibility to, say build a game for Linux and then build an interpreter function on other processors?
Would be nice to have no processor limits...
I think a hybrid version of your A and B is the best: game relevant data is to be calculated by the server and the clients only calculate the visualization and irrelevant stuff. There's still to define what is game-relevant and what not...
0
 
LVL 11

Assisted Solution

by:bcladd
bcladd earned 50 total points
ID: 9866820
The limitation is if you send byte sequences EXACTLY as they appear in memory. You will read (or have read) about network byte order? I can never remember whether it is little-endian or big-endian (Intel is, I think, big endian, PowerPC/Motorola are little endian and network byte order is little endian; in any case network matches Mac). The point is that all machines that have sockets have data marshalling functions that translate host formatted multi-byte quantities (integers of various types for the most part) to network byte order and others to translate network to host ordering (htons, for example, takes a short in host order and returns a short in network order; reverse routine is ntohs). Passing information in cannonical network order is useful if you expect to have many different types of machines communicating.

It is a pain if you only really expect to have one architecture (or mainly one architecture) and you know it isn't using network byte order internally: every int you pass is translated to and from network byte order FOR NO REASON. The fix is to choose your own cannonical ordering. Then, if you add a machine architecture that is different you make that machine's version translate to/from your main machine's byte order.

Calculating what is game relevant is hard. The problem is made harder by the fact that it is dynamic. Think about it: If the client is primarily for rendering sights and sounds for me then there is no need for it to get any updates about what the postman is doing as he loads his truck downtown. However, just before he gets to my door I might hear his steps on the walk, his knock on the door, and, opening the door I would want to kill him where he stands (this is an FPS, after all). Assuming I miss and he continues on his way, he will fade from relevance when he goes around the corner of the house...or will he? What if he just wanted cover and is going to double back in 1.2 seconds to fix me good?

Relevance is important because it limits the number of objects that need to be updated and so limits the required bandwidth.

-bcl
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Snyke
ID: 9866938
Well I would be using a struct to describe the entire player and update it all at once. This way I have a consistent image of where the players are and what they are doing. I always thought that using htons on systems that internally use network styled memory will return without doing anything...
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9867023
Correct. If you happen to match netowork byte order hton* and ntoh* are effectively nops.

-bcl
0
 
LVL 1

Author Comment

by:Snyke
ID: 9931478
Really good answers all of you... couldn't decide which answer to accept but since bcladd answered the first question his one's accepted.
0
 

Expert Comment

by:Cisan
ID: 9941453
Even though it has already been answered, here's how I solved the problem (and got a very lean and efficient network code).

First, use UDP. Build your own network message stack and your own syn-ack management. Not every packet "has" to reach its target (i.e. a packet where you update the player positions need not be ack'ed, there's no point in resending it. If it doesn't arrive NOW, it isn't needed anymore. In a second, the packet is worthless. A packet that sends e.g. the information that the player died or one that transmits a message MUST be resent to make sure it arrives. Whenever.).

What I did was to build a "pseudo transmission control" on UDP. I used the first byte of the transmitted data for a packet-ID and the second as a flag field, telling the other computer whether this packet needs to be ack'ed, if this packet is an ack (and if, the 3rd byte was the ID of the packet ack'ed) and a few more state related things.

This way you get almost the same reliability of TCP without the bloated overhead.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Cited: Konstantinos Dimopoulos URL Cited From: Article from Indie Games: http://indiegames.com/2012/07/browser_game_pick_the_grid.html The Grid (http://codeelf.com/games/grid/) is the sort of game I haven't played in over 10 years. It is …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question