Jump to content
  • Advertisement
Sign in to follow this  
Mats1

Starting out with networking

This topic is 838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm going to start out learning networking, with the idea to make multiplayer online games of various kinds. I have made a bunch of local games in GDevelop (2d game engine). Are there benefits to learning networking in raw C++ or using something like boost:asio? Or would it make little difference and should I just learn JSON (which GDevelop uses for multiplayer)? Also, are there any books, tutorials etc you would recommend someone starting out with networking should be reading/doing?

Share this post


Link to post
Share on other sites
Advertisement

I personally would not use boost asio as a learning tool.  It actually impedes learning as it has abstracted away most of the learning that could be had by struggling with the underlying sockets and such.  There are definite benefits to learning the underlying constructs as you will learn that writing portable code is hard (winsock, epoll, kqueues, etc) and you often are really only targeting 1 or 2 platforms anyways.  Additionally, the code base is very complex for a learner to go thru and furthermore you need to understand the trade-offs being made by the authors (design vs performance, etc).  All of that is much weight if your goal is to just learn networking.  

 

For me personally, I would go thru this if I wanted to learn basic networking.  

Share this post


Link to post
Share on other sites

I'm going to start out learning networking, with the idea to make multiplayer online games of various kinds. I have made a bunch of local games in GDevelop (2d game engine). Are there benefits to learning networking in raw C++ or using something like boost:asio?

If you're looking to make an online game in C++, go with boost.asio. Otherwise, since you'll probably build the game on Windows, you'll need to learn IOCP to get the full benefit of async network I/O. Then you'll realize a Linux server will be a more efficient and secure than a Windows server, and want to change over... good luck porting the core of your server, written in IOCP for Windows, to Linux (probably using epoll for async I/O). boost.asio wraps those APIs (and the equivalent on other OSes) in a portable fashion. boost.asio's "strand" concept is useful in non-IO contexts too, it allows you to schedule tasks that can't be performed concurrently in a safe manner, without stalling execution on a lock.
If you're not familiar with C++, though, developing a server in C++ is hard, even with the benefit of boost libraries. And last I knew there was no boost offering for managing the client's responsibilities (interfacing with the window manager, managing user input, drawing graphics, etc). Most of the system-specific and cross-platform APIs for that stuff, which are truly suitable for games as well, are written for C, which makes using them a bit harder. You might be better off at least prototyping in GDevelop if you've never used C++ before.

Also, believe it or not, C# might be a better option than C++ for making an online game. It's highly portable (thanks to Mono), has asynchronous I/O, user input, and (really basic 2D) graphics without third party libraries, and OpenGL bindings are available.

EDIT:
I both agree and disagree with Henderson. If you've never written any server code before, working with boost.asio will familiarize you with many important concepts. But it abstracts away all the nitty-gritty details and, like he said, the code is very hard to read through. If you're trying to make a game without too steep a learning curve or devoting too much time to network infrastructure, boost.asio is great. If you want to learn the most possible, and are less concerned with actually completing the game, it'd be worth working at a lower level.
Also, never work with actual RAW sockets without good reason.

Edited by nfries88

Share this post


Link to post
Share on other sites

Apart from the overhead when compared to Sockets, are there any huge negatives with using a RESTful Web API? This seems like the cheaper route to go when you can pay for some Azure web api services instead of picking up an entire VM to host the server on.

Share this post


Link to post
Share on other sites

I should clarify, that if you need real-time networking like an FPS shooter, i see the need for a full socket server. For games like a multiplayer chess game, social avatar game (2d second life styled) etc, would there be any major reason to avoid a web api for them instead of a socket server?

Share this post


Link to post
Share on other sites

Sure, you could do that, but you could also just use the the Azure hosted service to serve as matchmaker for NAT punchthrough and get the best of both worlds for those types of games.
:)

Share this post


Link to post
Share on other sites

Alongside Beej tutorials, I'd take a look at this too :

 

http://gafferongames.com/networking-for-game-programmers/

 

This is old school socket programming, simple and effective. But won't give you a lot of things other methods would. 

 

Can look at Unity game engine, or whatever game engine will facilitate making your game, and raknet, which is a well developed open source network library. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!