• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Incompletion

Server-Side Concept, Brief Explanation?

10 posts in this topic

Would someone be able to explain briefly/redirect me to some resources about how server-side programming works?

Edited by Incompletion
0

Share this post


Link to post
Share on other sites

How specific can I be? I want to know the process, for example, what would I need to handle inbound/outbound packets etc..? I have no experience with server-side so it's quite difficult to specify - otherwise I probably wouldn't be asking in the first place..

And no, I just want an explanation of how the system works rather than a code-specific explanation.

Edited by Incompletion
0

Share this post


Link to post
Share on other sites

Thank you Samoth, and yeah, at first I thought it would work that way but I wasn't sure, thanks for the answer though it was exactly what I was looking for.

As for ports, how would the interaction work? For example, is it client specific? Meaning only a certain game client is eligible to connect to the port that the server has been programmed to run off off? Or is it port specific, do you have to register ports in order to utilize them?

Edited by Incompletion
0

Share this post


Link to post
Share on other sites

There are always two (actually three) different ports with a connection (assuming you use TCP). The one the server binds and listens to, that is a number between 1 and 65535 that you choose (more or less deliberately). Assuming you're using the socket API, you pass that number as part of your [tt]sockaddr[/tt] structure (e.g. when calling [tt]bind[/tt] or [tt]connect[/tt] or [tt]sendto[/tt]). The other one is the number that TCP secretly chooses on either end to identify the connection. This is a number that you don't need to know and that you can't influence (at least not easily). The network stack will choose something that works, nothing to worry about.

 

With UDP, it is "somewhat easier" as there is no connection. Your client sends packets to the port that you choose, and your server receives them on that same port number (obviously you must take care they're both talking on the same port). It then sends back packets on the same or some other port number (it is very much preferrable to use the exact same one because of stateful firewalls!), and the client reads them from that port number.

 

In theory, you can use any port you want, with the exception that binding to a port that is already in use by another program will fail. In practice, you don't want to do that because it may confuse people (or client programs) and it may cause undesired effects and/or reactions. For example, if you run a game server using the port number used by eDonkey or Kazaa, then users using those programs and scanning on those ports will attempt to connect to that service on your server. Further, it might be that your hosting company filters out these ports, so you spend days wondering why nothing works (when you think it should work). Or you might get a cease and desist letter from your local movie industry representative because you're obviously running an illegal file sharing network on a large scale. Or, something else. It's best to simply not take those chances.

 

Do a Google search for "well-known port numbers" and use something that's not already taken, or at least something that is very unlikely to cause trouble. Also note that ports below 1024 usually require a privilegued process (this is not strictly a hindrance, but a possible security issue if you forget to drop rights after binding).

Edited by samoth
0

Share this post


Link to post
Share on other sites

There is the ever present question, of using TCP/IP or UDP/IP. So, UDP is faster and has less overhead. Still, I recommend to go for TCP/IP instead, unless you have really high requirements on network throughput and optimization.

Quoted for truth. Most programs (including most games) work just fine, without any issues, with TCP, and it is a lot easier to get right for a beginner.

 

Small nitpick: UDP is not faster, at least not measurably. UDP has a lower latency because there is no in-order delivery of a stream, but there are individual packets. A packet arrives or doesn't arrive. Or, it gets delayed and arrives some time later. TCP will do its best to deliver everything in order, waiting and resending as needed.

 

Using UDP, you would instead just consider a missing packet "lost" and move on (most of the time even if it arrives later, because by then it is no longer useful). If your data is such that a lost packet doesn't matter but waiting on the packet is more detrimental (say, position updates in a fast-paced game, or 5 milliseconds worth of sound in a VoIP stream), this works out much better. It is often much more disturbing to have a 3 second hiccup than a short click that nobody really notices.

 

The UDP header is a little smaller, so technically when the bits go through a modem, it's a little bit faster, too. However, on the internet and on your ethernet cable, it's all about "frames per second". A router will forward, say, a million frames per second, it doesn't make any difference whether a frame is 40 bytes or 1280 bytes (or 7168 bytes if jumbo frames are enabled).

0

Share this post


Link to post
Share on other sites

There is the ever present question, of using TCP/IP or UDP/IP. So, UDP is faster and has less overhead. Still, I recommend to go for TCP/IP instead, unless you have really high requirements on network throughput and optimization. With TCP/IP, you get control of the order of packets, and the possibility to send big packets. With UDP, you have to do the house keeping yourself. Of course, it all depends on you requirements.

 

A general note about server-side programming. I like to compare it with the Model-View-Controller pattern. The server side of programming usually consists of the Model part.

 

Also, it is not unusual that the server side need a database to communicate with. The database would then be used to store the state of the game (if it is stored).

 

FWIW: in my case, I am developing an FPS, and using TCP/IP.

 

(note: I typically also use non-blocking socket IO and have Nagle disabled).

 

 

the main reason was mostly that it is less effort.

one minor downside of TCP is that it "may" make sense to try to avoid congestion, which is basically a scenario where data is being sent at a faster rate than it can be transmitted to the client.

 

usually, this isn't too much of a problem with plain game updates for modern/fast connections, but can become a lot more of a concern if also streaming file or world contents (such as the server streaming map geometry, textures, 3D models, ... to the client over the socket).

 

so, for example, if large data is being sent, it may make sense to cut it up into little pieces and send these mixed with the other contents, and also keep mind of how much data is being sent to the client, ...

 

also, it may make sense to send messages (like world updates) in a reasonably compact format (like raw bytes, or Huffman coded or Deflated data), mostly as using a plain-text serialization (especially something like raw XML, but even something like plaintext S-Expressions or JSON) is enough to bog down even fast internet connections (IOW: you don't want to be sending entity updates with something like SOAP or similar...).

 

 

so, basically, this means like the low-level layer delivers tagged messages (say: TLV / tag+length+value), and then basically on top of this there is a protocol based around sending compressed messages or similar (maybe Deflated, maybe something more specialized).

 

note that the TLV itself serves a role:

it both eases in multiplexing the data, and makes it easier to determine when a complete message has arrived (if we don't yet have a complete message, we don't process it until the rest shows up), as well as directing various types of messages to be processed in different ways (such as an update message vs part of a file or raw-data payload, ...).

 

...

0

Share this post


Link to post
Share on other sites

Small nitpick: UDP is not faster, at least not measurably. UDP has a lower latency because there is no in-order delivery of a stream, but there are individual packets. A packet arrives or doesn't arrive. Or, it gets delayed and arrives some time later. TCP will do its best to deliver everything in order, waiting and resending as needed.

I think TCP is slower, but not because of larger headers.

 

 

When you send a large file as fast as possible with TCP it fills whole large packets of same maximized size, even if you call the send with uneven or small data. Thats what its made for, optimizing bandwidth usage in this case.

 

When you have a game you typically try to send only tiny updates at some regular interval. When you use TCP for that it gets a tiny message, thinks it doesnt have enough to fill a packet and waits uselessly until the timeout, then it needs to send the tiny package anyway and shortly after that your game wants to send a tiny message again and it waits again uselessly. If you sometimes send a large packet it will get split up and then wait for the timeout before sending the second part of it and the other end got to wait when it cant use the first part alone.

Now if you dont disable the nagle algorithm it gets much worse and it basically doubles latency because it always does not send the ack back cause it waits for a second incoming packet which will nearly never come in time for such a game. I know some popular MMORPGs did not even use the no delay option to disable the nagle algorithm, which made people suffer much more from lag, which lead to them tweaking the registry or even using paid proxy services like lowerping after they found out.

 

When you send a UDP packet its immediately send out, no waiting, no tweaking needed. You just need to resend lost packets manually when it was a packet that had to reliably delivered, which is more programming work.

 

That said I think people should really try to find some middle of the road protocol that combines some of the speed of UDP with the easiness of TCP and optional sending of reliable packets. With some googling you probably find something like that, but not as standardized as people probably reinvent this regularly when not going the easy way of TCP.

0

Share this post


Link to post
Share on other sites


Small nitpick: UDP is not faster, at least not measurably. UDP has a lower latency because there is no in-order delivery of a stream, but there are individual packets. A packet arrives or doesn't arrive. Or, it gets delayed and arrives some time later. TCP will do its best to deliver everything in order, waiting and resending as needed.

I think TCP is slower, but not because of larger headers.
 
 
When you send a large file as fast as possible with TCP it fills whole large packets of same maximized size, even if you call the send with uneven or small data. Thats what its made for, optimizing bandwidth usage in this case.
 
When you have a game you typically try to send only tiny updates at some regular interval. When you use TCP for that it gets a tiny message, thinks it doesnt have enough to fill a packet and waits uselessly until the timeout, then it needs to send the tiny package anyway and shortly after that your game wants to send a tiny message again and it waits again uselessly. If you sometimes send a large packet it will get split up and then wait for the timeout before sending the second part of it and the other end got to wait when it cant use the first part alone.
Now if you dont disable the nagle algorithm it gets much worse and it basically doubles latency because it always does not send the ack back cause it waits for a second incoming packet which will nearly never come in time for such a game. I know some popular MMORPGs did not even use the no delay option to disable the nagle algorithm, which made people suffer much more from lag, which lead to them tweaking the registry or even using paid proxy services like lowerping after they found out.
 
When you send a UDP packet its immediately send out, no waiting, no tweaking needed. You just need to resend lost packets manually when it was a packet that had to reliably delivered, which is more programming work.
 
That said I think people should really try to find some middle of the road protocol that combines some of the speed of UDP with the easiness of TCP and optional sending of reliable packets. With some googling you probably find something like that, but not as standardized as people probably reinvent this regularly when not going the easy way of TCP.


this is why people typically disable Nagle...

if Nagle is enabled, TCP will buffer things, and send packets when the buffer fills up to a certain amount.

if Nagle is disabled, it will generally send things immediately, which is better for latency, but also makes it a good idea to write the whole message to the socket as a single operation.
0

Share this post


Link to post
Share on other sites

As far as I remember there is still some buffering in TCP even if you disable nagle, it only prevents the "optimization" of only wanting to send an ack for every 2 incoming packets which interacts badly with other algorithms in TCP.

Edited by wintertime
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0