How do you create a multiplayer lobby

Hey everyone.

How would I go about creating a multiplayer lobby? I’m sure I could figure out how to code it if someone could just tell me what actually has to happen behind the scenes. By the way, I’m trying to use TCP, but if you think something else would be better, then please tell me. want to have the options to host a game or to join one. Then you can host a game with certain settings, which would then be sent to any conecting clients, or you could join an existing game by clicking on a game in a list or something and then clicking join. The thing that I can’t figure out is how to get each client to find all the possible games on the network. How would I do this? Is there a way to find all the ServerSockets that are on a network and are waiting to accept a connection, and if I do that, would I have to connect to each of those servers and then only launch the game on the one which I choose to join and disconnect from the rest? Any help would be much appreciated! :slight_smile:

James.

About finding other players in a network:

Make all your clients connect to the same server (lobby). Once a game is started, send both clients the info to find the other side: make one of the clients a host for that game, and let the other (selected group of) clients join that host. You make sure they all get disconnected from the lobby at this point. Definitly go with TCP/IP.

Riven,

Thanks for the swift reply!

Okay, I get what you’re saying, and it sounds pretty good, but I was wondering something else: is there a way to find the server without having to connect to a certain server first. I don’t really want people to have to connect to a certain server just to play the game, you know? I want them to open the lobby, and it just lists the games, no matter which network they’re on. Or is there a way around this? What I was trying to say is, is there a way around having a dedicated server? I want to be able to host a game, and then some friends could just find it and join it, without having to know my specific address or host name, ,and I would host the game, and they would be clients in the game. Is that possible? Is there a way to find all the host names on a network, specifically the ones that are hosting a game?

It is possible on a lan. The client will send a message to all the other ip-numbers on the lan. Use the subnet mask to find what ip nubmers to check. If a computer responds you add it to the game list.

Thanks tom.

That sounds logical too, and I understand how it would work with subnet mask. I’m pretty new to networking, so I actually have no idea how to code something like that. How would I find out the subnet mask? Also, how do you actually send a message to an IP address? I know that sounds ike a quite a newb queston, but I’ve only really worked with Sockets and things like that.

Thanks,
James

RTJ (Read the Javadoc)

For TCP{IP see java.net.Socket

For Multicasting, see java.net.DatagramSocket

If you are familair withsockets in other languages it should be pretty straight forward from there.

Not that for a lan Game you dont even really need a lobby IF all the paleyrs ona lan are going to be assumed to be in the same session, just do a multicast to find each other.

Btw… I wrote a chapter for Practicla Java Game Programmign that already contains al lthe code you need to do multicast discovery on a lan.

Is it in Jeff speak too? :wink:

Local lan is definitely a multicast afair (as Jeff already said). The best bet with lobby servers IMHO is to keep it as simple as possible on the server side. You need chat, you need game requests, but thats it. Centralised servers work best but this of course means finding a host somewhere to run the server for you (which can get expensive). Generally better from a hobbiest point of view is to write the lobby server code, provide it to your player base for free and let the popularity of the game cause someone with hosting to set the server up for you.

Kev

Okay, thanks guys.

I’m going to try and code that now. I suppose a lobby isn’t really what I wanted after all, I was actually looking for something more like what Kev described, where the clients just do a multicast to find eachother. Kev, any chance of you giving me some code snippets from your chapter in that book?

Thanks,
James.

I think you’re looking for Jeff, he wrote the chapter, not me :slight_smile:

Kev

Oh, sorry :-[ . I got you guys mixed up (no offence to whichever one of you thinks you’re cooler than the other).

Oh Kev is MUCH cooler then I am :slight_smile:

Here is teh Amazon url…

http://www.amazon.com/exec/obidos/tg/detail/-/1584503262/qid=1118606837/sr=8-1/ref=pd_csp_1/102-9550393-2860934?v=glance&s=books&n=507846

Note that Shawn Kendall is releaing an update next year that repalces hsi scene graph stuff with Java3D,
When he started the first edition, the future of Java3D was unknown so he avoided it, but it looks
pretty solid now.

No way is Flanders cooler than Alf, come on…

I mean its Alf!

:wink:

Kev

Jeff, sorry man, I’d like to buy your book, but I won’t. I’m just going to mess around with multicasting for a bit and see where that gets me.

Thanks for all the help guys.

Well, you could go to the library and xerox it, or hand copy the code…

JK