Problems registering at AoCZone?
You can try resending activation email. If that doesnt work you can send an email here. If you forgot your password click here.
 Main Menu

 ForumsSearch »

 The Medieval Wars 2013

 AoE2HD Recorded Games

 AoC Recorded Games

 AoFE Recorded Games

 Current Tournaments

 Major Past Tournaments

 Auto downloadedFind »

 Users currently online
Staff (1)
Members (61)
»  asdfg
»  Edie_
»  HJFE
»  JUDAS
»  Jupe
»  kutz
»  mrn
»  PaTiN
»  xeous
»  Xtasy
»  YanBG
Guests (63)

 AoC Clans Add yours »

 Links

 Ads

Programming discussion - How to write a lobby server

Hang out and relax, everyday discussions, chit-chat, off-topic, wololo

Programming discussion - How to write a lobby server

Postby  kaymera » Sun Oct 30, 2011 5:32 pm

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.
 kaymera
 
Posts: 56
Joined: Apr 10, 2010
 
 

Re: Programming discussion - How to write a lobby server

Postby  pooos » Sun Oct 30, 2011 6:47 pm

might be useful... viewtopic.php?f=102&t=57434
 pooos
Gameposter Novice
 
Posts: 1432
Joined: Mar 14, 2010
Age: 38
 

Re: Programming discussion - How to write a lobby server

Postby  kaymera » Sun Oct 30, 2011 7:21 pm

It sure is! Thank you.
 kaymera
 
Posts: 56
Joined: Apr 10, 2010
 

Re: Programming discussion - How to write a lobby server

Postby  [EIF]BokiSergy » Tue Nov 01, 2011 1:45 am

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 ;)
Image
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

Postby  kaymera » Tue Nov 01, 2011 1:58 am

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? :mrgreen: )
Last edited by  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

Postby  fallingstar » Tue Nov 01, 2011 2:03 am

  01 Nov 2011, 00:58 GMT » kaymera wrote:
What's buga-pedia ? It won't open. (Was it a joke? :mrgreen: )

hahahah
Try http://www.buga-TheGreat-pedia.com :P :P :P
http://www.twitch.tv/directory/game/Age%20of%20Empires%20II:%20The%20Conquerors
User avatar
 fallingstar
Gameposter God
 
Posts: 4777
Joined: Mar 22, 2011
 

Re: Programming discussion - How to write a lobby server

Postby  kaymera » Tue Nov 01, 2011 2:05 am

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

Postby  [EIF]BokiSergy » Tue Nov 01, 2011 5:22 am

  01 Nov 2011, 01:03 GMT » fallingstar wrote:
  01 Nov 2011, 00:58 GMT » kaymera wrote:
What's buga-pedia ? It won't open. (Was it a joke? :mrgreen: )

hahahah
Try http://www.buga-TheGreat-pedia.com :P :P :P

Man, how came u dont know for Buga-pedia, its resource from where all community gets all informations :D <3
Image
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

Postby  Biz » Tue Nov 01, 2011 7:47 am

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
 Biz
 
Posts: 272
Joined: Feb 04, 2011
 
 

Return to Community Café

Who is online

Users browsing this forum: No registered users and 0 guests

Legend: Global moderators, News posters, Tournament moderators