Best approach for networking a board game?

Hey guys, it’s been a while since I’ve stopped by. The new forums look great!

I have a question about writing a networked board game. I’ve been looking into doing my network code via NIO, but several problems arose, including an inability to find information on it, and hearing that it has a lot of annoying bugs. So, I figured my best bet would be to ask you guys, since you know what you’re doing. :slight_smile:

I’m writing a board game that will support 2-8 players, and will need to be able to send objects (or at least data about the object) to other players. I also need to implement a chat feature. Reliability in regards to data sent/received is an important factor. So, here are my questions:

Which is more suited to my project, NIO, or IO+Net?
Should I use TCP/IP or UDP for this project? (I’m thinking TCP will be required, but I’m not sure how it works with a P2P setup.)
Is Peer-to-peer or Client/Server the best approach? (I want people to be able to connect to other players without a need for a central server.)

Thank you for any guidance you can give me!

I have limited knowledge on this subject so feel free to thorw out everything I say, but… If you need data transfer reliability then you needto use a TCP connection and I think that you would need to use a central cerver to make all of the players aware of each other. If you didn’t then each player would need to set up a P2P connection with each of the other players instead of simply connecting to the server and letting it handle all of the messy stuff!

In fact this is the set up we used to make a “BW3 / Bar style” trivia game! Where the server gives out a question and 4 answers, then a hint is displayed every so often and the sooner you get the right answer to more points you get!

Are you sure I need a central server, i.e. a Web server that continuously runs a daemon thread (or whatnot) for clients to connect to?

We just wrote another Java application that accepted incoming connections, it wasn’t to bad, but as I said my experience is pretty limited so if anyone else knows a better way, I’d like to know too! :wink:

The big issue with P2P is how you find each other.
If you are going to go peer to peer, the next question is, is it local LAN or Internet? If its LAN you can use the brodcast based game discovery code I presented in Practical Java Game Programming.

If its going to be an internet game it gets a lot more complex. If you dont mind your players entering each other’s IPs and you don’t have any firewall concerns then you can do without the server for an internet game, otherwise you need some kind of marshalling server out there.

Given the hig hlatency tolerances of this kind of game your choices are almost unlimited. This is even one of those rare game types where you could do quite a reasonable server as a J2EE servlet. Using a servlet has the advantage of using HTTP to cmmunicate, which almost everybody can get out of even the most restrictively firewalled networks. Be aware however that there is no solution for direct peer to peer over the internet that will penetrate typical consumer firewalls without a server to at least do UDP “introducing”

What Id personally suggest for this kind of game, if your goal is internet play, is going the servlet based server route.
.

BTW.

Ive done a number of NIO based projects and so far had no bug issues.

HOWEVER NIO is a lot hard to use correctly then java.net, and its pretty pointless for clients who are only going to handle a handful of open sockets at a time. NIO is really intended for serevs that have to handle O(100) or up connections at once.

Thanks for the info! Firewalls are a concern for me (since I don’t need to be flooded with complaints about how the program doesn’t work), so I’m thinking what I need is a client/server architecture. It also makes more sense considering the type of game, which will need a “host” of sorts. I’ll do a little more reading on the advantages and disadvantages between client/server and P2P (since that info is considerably easier to find). Thanks again! ;D

If you want to do P2P through cosnuemr firewalls (without reauiring the users to map ports on their firewall) you’ll need to do what is usually called “UDP Punchthrough”. If you google on that youll find lots of explainations. The key is that it still needs a server to act as an “introducer” that gets the session started.

Given the kind of game you are doing, if you have a host available that will run servlets for you, I’d strongly suggest that an HTTP servlet based server/client solution will likely be the simplest solution.

Good luck!

I have already created exactly same games as you are planning to do (see the site in my signature)

  • it has client / server architecture, it communicates through TCP
  • the server is java application. But Jeff’s suggestion is good. If I had to start again from scratch I would consider servlets
  • at the beginning I used old java IO for both server and client, but I encountered very annoying problems, so I re-worked the server to use NIO. It works great now. The clients (applets) still use old java IO, for clients it’s ok

Using the servlet method as suggested, could you describe the communication between the servlet and the client?

And more specifically, I’m working on something like this that will likely use Flash as the client. Is there anything I should be aware of in that case?