Jump to content

Is networking really that hard?


ADIGEN
 Share

Recommended Posts

Please bear with me, I am completely new to game networking. Any help and improvise in this question will be appreciated!!!

I have been playing around with BJS (babylon.js) for a while now, wanting to make a real-time multiplayer game.

I have been searching around the web about game networking, and read this:

https://github.com/gafferongames/gafferongames/blob/master/content/post/what_every_programmer_needs_to_know_about_game_networking.md

It gave me a clear idea of how should I go ahead. But in all the forums, I hear people saying game networking is very hard, not to waste time on it rn, and stuff.

So I thought to give it a try. I used node.js for server with socket.io to communicate to the client back and forth. What I did was, when I receive the server's update about the location, I would compare that to the location of the client (which was predicted, or more like comprehended on the client side) to check whether the difference was under 0.1 (or any number). If it was not, I would redirect the player back to location sent by the server. (there is still some minor jitter in the gameplay)

After doing the above, I felt it like a piece of cake. I felt on top of the world! But, I was still trying to figure out what people really meant by "hard".


So after bit of more research, I found out nengi.js, a game networking engine for node.js. I noticed people comparing socket.io and nengi.js. Aren't they two different things? socket.io is used for bidirectional communication between client and server, and nengi.js is a game networking engine! This has created a huge confusion in my head. Could anyone please help me with this?

Also, please clarify whether the process I did above for client prediction is correct or not?

If you need anymore details/info, please let me know!

Thanks a lot for reading through! Thanks in advance! 

Link to comment
Share on other sites

Its not, its just amount of work to make it right for your game is big. There always be people who complain about lags, and you have to be balanced about effort you spend on them. Suppose 100 people joined your game, and 10 had bad connection. 10 left. Now, in a month or two situation in network changes, and 9 from those 90 have lags, they leave, but those 10 previous guys don't join back just because their network became better :)

Client prediction depends on you game, and if you have players very close (touching) and that affects gameplay - even slight lag will make experience bad.

I made my IO game (gameofbombs.com) in 2012-2013 I was very lucky for it to be playable, i didnt know anything about networking experience of past games and i did it!

Made it better in 2014-2015, and from 2017 I hired the only guy who understood my algorithms and he's making new version of engine that will have much less lags. Its going on for 3 years already and its very hard.

Of course you can use nengi to start, but networking is very big and you dont stop there, you'll have to modify it for your game.

Link to comment
Share on other sites

Thanks a lot @ivan.popelyshev! I checked out your game! The one I want to make is a third-person space craft battle game, which is gonna be fast paced. Should I just go with the method I mentioned above (the difference should be below 0.1), or should I go with nengi. Is nengi a worth upgrade than the method I used (my method involves really nothing lol)? If yes, I would like to see any other alternatives to nengi just to have an idea (or if it is the best out of all, then I might directly use it!)

Link to comment
Share on other sites

There's also a matter of lost packets that seriously affects TCP networking. Any lost packet induces a lag spike. There's a trick to maintain two-three websockets connections instead of one, and sending a packet into - but nobody implemented it in public, its very limited. It also requires UDP-like architecture of client/server, that's one of difficulties we're trying to solve.

Link to comment
Share on other sites

I study networking too. This tutorial is awesome: http://buildnewgames.com/real-time-multiplayer/

You can download and run locally a code from the tutorial from here: https://github.com/underscorediscovery/realtime-multiplayer-in-html5

I deploy the code on free hosting Heroku: https://battle-world.herokuapp.com/?debug You can run the app in two browser tabs and test how smooth it.

Network programming hard because network latency. The author uses client prediction and interpolation. We need to train by making simple games to study it on practice.

I think Heroku is the best place to practice. If no one run uses your app during 30 minute the server will sleep but it wakes up very quickly less then 10 seconds. It is a free plan. You can pay $7 in month if you do not like this. Your server will not sleep if someone uses it. You can connect your private (or public) GitHub repo with Heroku and when you push the Heroku will auto deploy your application.

I use TypeScript on clients and on Node.js server because TypeScript is the best for web games. If you use Unity and C# too you will like TypeScript. I study how to write server in C#. C# is better than C++. And it is fast too. Network latency makes their speeds the same.

Link to comment
Share on other sites

I use SocketIO and Babylon.js for 3D client too. Babylon.js was written in TypeScript and it very friendly to TypeScript. If you want to switch to TypeScript in the future I can help you because I know about it a lot now.

We need to have a lot of practice because only that way can be true. Try to deploy your first "Hello from Server" application on Heroku. You need to connect to the server and the sever will send "Hello from Server" application and you need to print this message in browser console. Try deploy your first application on Heroku and I can help you: https://www.heroku.com/ I know everything about how to do it.

Link to comment
Share on other sites

  • 2 weeks later...

Let's create the simplest network game: Tic-Tac-Toe. I recommend to start with hosting on Heroku. Make simple connection to your server on Heroku. Create a private (or public) repository on GitHub and connect Hekoru with GitHub repo in Deploy Setting of Heroku. It is the best solution to practice with live server and with simple games like: Tic-Tac-Toe, the Russian fool (Durak) game (and another simple card games), the battle sea game, checkers, chess, the game go, the classic snake game and  so on. Avoid real time games for a while. Real time games are very hard for smooth movement because network latency and they require methods to decrease network latency that described in this awesome article: http://buildnewgames.com/real-time-multiplayer/

I use pure WebGL 1.0 and GLSL for client because I love to study mathematics (linear algebra, geometry and trigonometry). I like to study how to write my own simple lightweight graphics and game engines in 2D and 3D. I write client and server in TypeScript because this language are the best for game development.

Writing Unit Tests is very important in modern development. I study how to write mock-objects using Jasmine for client, server and shared classes (shared between server and client). We can write mocks for databases (free Heroku support: MySQL and MongoDB, I prefer MySQL and SQLite). And we can write mocks for network and for another classes that we (or someone from our team) have not developed yet. I like to study TDD (Test-Driven Development). Unity Testing and TDD can be very useful for game development but writing testable code requires a lot of practice.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...