Hello,
I was just wondering about famous game like Agar.io that how can we achieve such result for multiplayer game?
It has so many players in one room with real time multiplayer.
If we use sockets for our own server for such games then can we achieve such result?
Any info would be great.
thanks,
Smit
1 Like
Sure you can , you can use the cocos websocket client .
And use netty for java which have already build in websocket handler .
By blog Tutorial about using netty and cocos
Or node.js which handle websockets also .
Thanks for reply. @Meir_yanovich
So by using that way, can it handle such traffic for single room?
I think Agar.io has more than 50 players in single room.
Thanks for this, i saw this earlier. Do you have C++ tuto too?
I use C++, still it will help me.
You can handle 50 players its all about your OS settings and hardware not netty .
( open file descriptors limit and such best in Linux for java … ) .
For c++ you will need to build custom solution , but remmber that c++ will give you the best results .
That means if you what to use Async connections and WebSockets
use network frameworks like :
libuv + websocket client compiled statically use the one cocos is using .
libuv book
keep the server simple not general purpose that means api specific for you game. and you will be fine .
to design your game server architecture the best description i saw on line is this one :
simply do it in c++ .
if you need example of usage sockets with C++ here is mine: go here
you can handle as much players as OS can open potencial remote ports (65536) but you need to calculate RAM for this amount of players.
But dont you think client side also matters??
Suppose 50 players are there, then each player will get all other players update on each frame/movement.
I mean C++ at client side. I want to use Java at server.
But i will look into libuv too.
Do you think C++ at server side will be more complex?
And thanks for tips.
Thanks for reply @camkadev
What are you using at server side?
and How to calculate that? Ofcourse it will depend on the server game logic but still.
@smitpatel88
Well its all depends , there are some articals on the web which deal with this matter in high level you will have to design the game protocol to be Smart enough to use small data structures as possible .
also remember the game logic is calculated on the server first (!!) so you returning back only the deltas and which player moved to the client .
on the client side you have cocos c++ web socket client just wrap it with your logic .
if you want to use pure tcp sockets i suggest you to use : Oculus rift open source BSD RakNet client
i suggested the cocos developers to make this lib part of the engine .
@Meir_yanovich
RakNet is too complex to understand how to use them and look at last commit, it is 2 years ago, so, if Chukong Inc will include it into cocos2dx and some one find bug, who then fix bugs?
@camkadev
Well from my experience in my day job as c++ server developer in the telecom industry i most tell you
That you have only few industrial well proved c++ cross platform network lib’s and they are :
Boost.asio
ACE
POCO
They are to complex and big for cocos2d-x or game engine .
From what i know RakNet has bean used allot in the gaming industry and have some proved record .
Its small cross platform and i guess if there are bugs they can be fixed .
@Meir_yanovich
well i must to agree with you, i looked at POCO and Boost and that is a really big stuff, so that is a reason i write socket myself with help of China friends.
i will look at RakNet implementation at the future.
@camkadev
My suggestion is dont use your own network lib , there are to many things in networking that you need to handle its a mess and very time consuming .
@smitpatel88
i found about the answer which talk about the server side on Agor.io and i was right the developer is using libuv
see info about the game (search libuv ) :
https://news.ycombinator.com/item?id=9462967
also see this :
How much does Agar.io monthly pay for servers?
Game growth-hacks
I know libuv very well if there is demand i will consider to make tutorial on the subject .
@Meir_yanovich
yeah you right, network programming is another big science
As far as I think, only the area which is visible to player gets updated which includes only that area would be rendered on the client side which is actually visible.
Also, there are sometimes way more than 50 people on the same board. 
In case of which agar.io server side should be checking overload and would be shifting those users to different board having less load.
Also, there is some agar.io open source code. You may check that on git.
Ofcourse.
I read that earlier but didn’t read about libuv over there. Thanks for pointing it out.
That is some mind blowing amounts. 
I think you should make one with just small demo. By that all beginners(For multiplayer) like me will get great boost.
+1
Yeah, means server will send updates of those players only which are in my near areas, in that way we can have a lot small num of msgs.
Ya, thats fine. We can apply same logic as pocker room handing.
Yes, so the client side won’t become slow!
(Same happens when the skins on the balls are loaded. Only those skins are cached whose player is nearby and once loaded chrome always get the images from cache rather than server)
But still I wonder sometimes, how come it still becomes laggy at times.
So, I feel that server might become slow while processing lots of objects.
Suppose, 100 players are playing and each of them is split up in maximum balls. So, now 100*10 balls objects are stored and each objects have atleast 4-6 properties!.
This is what should be making game slow! not the client side.
This might be the reason that www.agarly.com is laggy even when only 10-20 players play on it!
Bcoz there servers might not be able to handle load properly or their server RAM would be less!
Just try playing www.agarly.com… Another super addictive version of it.
bombermine online is another one beautiful online multiplayer game, i think server is similar to Agar.io
@camkadev
I know the bombermine online developer i spoke with him few times the server based on Java netty or jetty
he is was one of the maintainers of pixi.js ( mybe even now )
@catch_up @smitpatel88
Keep in mind that its 1 developer show . and the server is not perfect even far from it but its good enough
this prove my point dont Get stuck on which server stack to develop its never going to be perfect , just put it online and iterate