Hi guys,
I am discussing with Voobly the idea of adding Chess to supported games. I have a working prototype (screenshot http://goo.gl/pYqM3) but I have big doubts regarding some things I did with the server. Writing a Voobly-like lobby server is a new programming experience to me and so I don't have a clear nor precise programming model for it. I also couldn't find a paper that describes how it should work. I asked Elusive (Voobly main developer) for some insight but appearantly he's busy for now. I bought "Java Network Programming 3rd edition" from Amazon and still waiting for shipment, hopefully I'll find some useful examples/information in this book.
Meanwhile, I'd like to gather opinions from the programmers here (BugA, Boki?) and see how they would handle things so I can learn how to write a server correctly. Here are a few questions off the top of my head: (may be more will come)
First, let's define what a server does. It's primary functionality is to hold TCP connections with clients, listen to the events they generate and dispatch them to the other players. But is there more to it than that?
Should I use one thread per client? If so, 300 clients = 300 threads. Isn't that too much? What hardware is needed to support that? And how much bandwidth does a lobby consume then approx?
What kind of data structure should be used to hold the clients' sockets? How do you protect it from concurrent access when iterating through it to dispatch an event without hurting throughput?
When a user enters the lobby, what mechanism would you use to transfer the state of the lobby to him? And while this is happening, where do the other events bubble up?
Input is greatly appreciated.
Programming discussion - How to write a lobby server
Re: Programming discussion - How to write a lobby server
might be useful... viewtopic.php?f=102&t=57434
-
pooos
-

- Posts: 1432
- Joined: Mar 14, 2010
- Age: 38
Re: Programming discussion - How to write a lobby server
It sure is! Thank you.
-
kaymera
- Posts: 56
- Joined: Apr 10, 2010
Re: Programming discussion - How to write a lobby server
hey friend, I am not so experienced but I ll try to help a bit.
Ok, lets see, first of all lets we start from client. Client should gather few people into a room, then it should start game. There should be protocol which would pass two users ( or more if they wanna watch or play some coop game). Game itself should just give back result of the game, and maybe some statistics, rec of the game... After u have to verify result, and send result to the server. There are severals ways how all this can be done. Even the principle could variate, for example game could be loaded into the client ( as some kind of module ), so u dont have additional exe ( jar or etc file )...
Communication with server can be done in several ways. It depends what type of server is. I really cant say, what is the type of the server in Voobly ( what software runs inside) , but u really dont need to know. All uhave to know is how this server communicates with the client.
If u want to write ur own server, then I sugest u to use Apache like server, and write ur program in PHP. Then u could easy manage users through a database, and PHP program itself would be sued to access the database and stores ur result. Easiest way to do this, is to make client which would list players attached to the server, and make option to host room, join, etc... Then u just store infos in database, using PHP program on the server. U can use lets say POST methods to pass result from game to the server. Or encrypted LINK methods... dunnno what exactly should used, which would be best in this case since it should hack safe. We could do this, all we need is to buy some hostname, we could use also a free hosting.. but we should ask lets say PKZ, what he thinks how fast it would be ( it has to support like 1000 users in every moment )...
If u are interested and will, we could do this part together. Probably biggest problem in ur project is to animate Voobly devs and make Torm and rest of Voobly, to work . Problem is that Torm know exactly how their server works, but hardy give informations. Even u have these informations, still u have to have cooperation between developing ur project and protocols which Torm should develop. Client is written in Pascal, btw. And btw2, if u make client of ur own game, then u can easy bypass all these TCP/IP things. For chess, server itself can manage inforamtions between players, such is "e5" "Nf5"... u dont need addtional connection to another player..
More about this on http://www.buga-pedia.com
Ok, lets see, first of all lets we start from client. Client should gather few people into a room, then it should start game. There should be protocol which would pass two users ( or more if they wanna watch or play some coop game). Game itself should just give back result of the game, and maybe some statistics, rec of the game... After u have to verify result, and send result to the server. There are severals ways how all this can be done. Even the principle could variate, for example game could be loaded into the client ( as some kind of module ), so u dont have additional exe ( jar or etc file )...
Communication with server can be done in several ways. It depends what type of server is. I really cant say, what is the type of the server in Voobly ( what software runs inside) , but u really dont need to know. All uhave to know is how this server communicates with the client.
If u want to write ur own server, then I sugest u to use Apache like server, and write ur program in PHP. Then u could easy manage users through a database, and PHP program itself would be sued to access the database and stores ur result. Easiest way to do this, is to make client which would list players attached to the server, and make option to host room, join, etc... Then u just store infos in database, using PHP program on the server. U can use lets say POST methods to pass result from game to the server. Or encrypted LINK methods... dunnno what exactly should used, which would be best in this case since it should hack safe. We could do this, all we need is to buy some hostname, we could use also a free hosting.. but we should ask lets say PKZ, what he thinks how fast it would be ( it has to support like 1000 users in every moment )...
If u are interested and will, we could do this part together. Probably biggest problem in ur project is to animate Voobly devs and make Torm and rest of Voobly, to work . Problem is that Torm know exactly how their server works, but hardy give informations. Even u have these informations, still u have to have cooperation between developing ur project and protocols which Torm should develop. Client is written in Pascal, btw. And btw2, if u make client of ur own game, then u can easy bypass all these TCP/IP things. For chess, server itself can manage inforamtions between players, such is "e5" "Nf5"... u dont need addtional connection to another player..
More about this on http://www.buga-pedia.com

love songs:
"Aganju": http://youtu.be/J71FLwVNps8
"Girl from Ipanema: http://youtu.be/UJkxFhFRFDA
"One Man's Dream": http://www.youtube.com/watch?v=ubTveCihjoQ
-
[EIF]BokiSergy
- Posts: 1821
- Joined: Mar 29, 2010
- Location: Belgrade, Serbia
- Age: 27
Re: Programming discussion - How to write a lobby server
Thanks for your response Boki
The idea is to write my own version of the server and use Voobly database for persistence. I have done most of the work : chess logic, protocols, communication and server. The only problem is that now it works with a few players but it will not scale. For example, the server maintains a map with player id as key and player socket as value. When a player generates an event (eg writes something in general chat) the server dispatches this to the other players by iterating through the map and locking it to prevent concurrent modification. Let's say there are 300 players online generating various events, the threads on the server will contend too much for the map lock and throughput and service time will suffer. Later, I have come to learn that there's a map implementation designed for concurrency, ConcurrentHashMap, but I don't know how good it really is and whether replacing my map instance with a ConcurrentHashMap will be sufficient to support 300 players.
There's also the thread per client problem. I am not sure about this design, I worry 300 threads is too much. I don't know if Elusive does that. There seems to be another model where the server doesn't keep one thread per active connection but instead keeps a list of the connections and then have a single thread poll the connections periodically to see if there's events at the TCP layer pending to be dispatched and notify some listener.This would cure the server from too many threads but at the cost of lower service time..
I could probably figure out how to write the server well if I had a means to test it under moderate and heavy load (200 - 300 connections in one lobby) but I would need actual users. How do I do that?
I think I will write some kind of bot, populate the server with many instances, and see how it behaves. I don't know how viable this is but I'll try.
What's buga-pedia ? It won't open. (Was it a joke?
)
The idea is to write my own version of the server and use Voobly database for persistence. I have done most of the work : chess logic, protocols, communication and server. The only problem is that now it works with a few players but it will not scale. For example, the server maintains a map with player id as key and player socket as value. When a player generates an event (eg writes something in general chat) the server dispatches this to the other players by iterating through the map and locking it to prevent concurrent modification. Let's say there are 300 players online generating various events, the threads on the server will contend too much for the map lock and throughput and service time will suffer. Later, I have come to learn that there's a map implementation designed for concurrency, ConcurrentHashMap, but I don't know how good it really is and whether replacing my map instance with a ConcurrentHashMap will be sufficient to support 300 players.
There's also the thread per client problem. I am not sure about this design, I worry 300 threads is too much. I don't know if Elusive does that. There seems to be another model where the server doesn't keep one thread per active connection but instead keeps a list of the connections and then have a single thread poll the connections periodically to see if there's events at the TCP layer pending to be dispatched and notify some listener.This would cure the server from too many threads but at the cost of lower service time..
I could probably figure out how to write the server well if I had a means to test it under moderate and heavy load (200 - 300 connections in one lobby) but I would need actual users. How do I do that?
I think I will write some kind of bot, populate the server with many instances, and see how it behaves. I don't know how viable this is but I'll try.
What's buga-pedia ? It won't open. (Was it a joke?
Last edited by
kaymera on Tue Nov 01, 2011 2:09 am, edited 1 time in total.
kaymera on Tue Nov 01, 2011 2:09 am, edited 1 time in total.
-
kaymera
- Posts: 56
- Joined: Apr 10, 2010
Advertisement from Google 

Re: Programming discussion - How to write a lobby server
What's buga-pedia ? It won't open. (Was it a joke?01 Nov 2011, 00:58 GMT » kaymera wrote:
)
hahahah
Try http://www.buga-TheGreat-pedia.com
http://www.twitch.tv/directory/game/Age%20of%20Empires%20II:%20The%20Conquerors
-

fallingstar
-

- Posts: 4777
- Joined: Mar 22, 2011
Re: Programming discussion - How to write a lobby server
Ah lol. I know BugA is good. I hope he posts 
-
kaymera
- Posts: 56
- Joined: Apr 10, 2010
Re: Programming discussion - How to write a lobby server
01 Nov 2011, 01:03 GMT » fallingstar wrote:
What's buga-pedia ? It won't open. (Was it a joke?01 Nov 2011, 00:58 GMT » kaymera wrote:
)
hahahah
Try http://www.buga-TheGreat-pedia.com![]()
![]()
Man, how came u dont know for Buga-pedia, its resource from where all community gets all informations

love songs:
"Aganju": http://youtu.be/J71FLwVNps8
"Girl from Ipanema: http://youtu.be/UJkxFhFRFDA
"One Man's Dream": http://www.youtube.com/watch?v=ubTveCihjoQ
-
[EIF]BokiSergy
- Posts: 1821
- Joined: Mar 29, 2010
- Location: Belgrade, Serbia
- Age: 27
Re: Programming discussion - How to write a lobby server
just queue all lobby chat events... dont try to do things syncrhonously if you are using hundreds of threads
you only really need locks for each game room
you only really need locks for each game room
-
Biz
- Posts: 270
- Joined: Feb 04, 2011
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests
Legend: Global moderators, News posters, Tournament moderators
Main Menu
__Duck
_DK_
alexriopreto2012
ALEXXXX-
cosmi23
CULT_Scream
DbZ_Giru
Death_Warden
htc
hunwar
Katsuni
Nicov
Smotp
vaitomanocu










