1

I'm trying to create a one on one, turn based board game in java. The basic game structure is already created and working if the players are on the same computer. I am now struggling to implement online multiplayer, because I have never done anything network-related before.

Each turn the player has to enter up to 9 decimal numbers (if a number is left out it is considered to be 0). Since I want to allow arbitrary precision I stored those numbers in an array of BigDecimals.

The way I imagine it to work, the two clients can connect directly to each other via IP, exchange messages each turn and get notified once the other client disconnects.

I have tried looking into several different tutorials, but they didn't work for me either because they implemented a server/client solution or because they didn't allow me to send the BigDecimal Objects. By now I am a little confused about the subject and unsure where to start implementing the network connection. That is why I don't even have any code to post here yet.

Sebastian
  • 11
  • 2

1 Answers1

0

If what I understand from this post is correct, you cannot create a simple connection between two clients. You must have some sort of server in between, or else one of the clients must function as the server. There is no easy way to connect two "client sockets".

That being said, I'm not sure if it's possible to create a connection over a LAN. I've personally played games where you need to set up some complicated stuff to be able to play online over the internet, but two people sharing a LAN connection can connect easily with no problem. The post I mentioned before touches on that, but I haven't really done enough research to know half of what they're talking about in there.


Additional information:

This is what Oracle has to say about connecting through servers and sockets, etc. They may be able to provide some additional support, even though their article discusses a situation with three clients whereas yours only has two.

Good luck with your game, hope this helps!

Community
  • 1
  • 1
  • Thanks for your answer! If it's not possible to connect two "client sockets" would it be possible to give the clients the ability to be a server for this single connection? I don't really intend to set up a permanent server for this little game of mine. – Sebastian Jan 28 '13 at 21:05
  • I don't believe so, since the server and the client run two different programs. If anything, you might be able to find some alternate solution outside of Java, and incorporate it into your programs. I understand that you're trying to keep your program small, however. An example of an external solution may be to set up the program so that it interacts with your system to create a remote desktop connection, which allows the users to play on the same computer while really they are not together. This may be difficult, though, and the code would be pretty fragile after that... –  Jan 28 '13 at 21:15
  • I have seen a two player game operating over network without a server [here](http://www.webpelican.com/internet-programming-1/magnificentball/). So I am pretty sure it is possible. However I don't understand whether or not they can be aware of the other game disconnecting or how I could send the BigDecimals. This linked game is sending strings. – Sebastian Jan 28 '13 at 21:38
  • I don't really know. Looking at the screenshots, it appears that one player acts as a server while the other is the client. However, I couldn't tell you for sure. Maybe the programmer who made this would be able to tell you, he has a "Contact Me" link in the About page on the website you found that game on. –  Jan 28 '13 at 22:04