3

I'd like to implement a simple chess peer to peer network application : one instance of the program may register friends player, and when one friend is "connected" (I mean both available by another program instance and registered as friend), I can ask him to play a game.

As I know J2SE language, as well as Swing framework, I tried to start coding, using Sockets. The problem is that I need a way to

  • register my friends (or other accounts)
  • get the friend ip, for creating a socket (it will be the same problem on the other side) : with the problem of dynamic ip adresses.I mean that a serialized adress may not be valid anymore
  • be informed that the other side has "connected"

I think that first and third point can be resolved if I use a PHP server which will have all informations for all registered users.

This is how the application should work :

  1. First, before trying to connect each other, the users must register an account on a PHP server that I'll have to implement (with MySQL database)
  2. When launching the application, the user logins by giving its username and password. So that the application will be able to retrieve friends (and stats for example) thanks to the server
  3. When two friends are ready to play together, the server give all needed informations (such as ip adress) to both player application instance.

My main difficulties will be for the (de)serialization of dynamic IP Adresses, and for retrieving informations about a user on the PHP server.

What do you suggest ?

Konrad Morawski
  • 9,721
  • 4
  • 37
  • 58
loloof64
  • 137
  • 9
  • You are trying to write a peer to peer chess game rather than a client / server structure? Neither is wrong - but they do have significant implications on the first and second problems. What does registering in a peer to peer system mean? How does a peer get the IP address to connect to of another peer? –  Apr 04 '13 at 19:32
  • I want to code a peer to peer application. – loloof64 Apr 04 '13 at 19:33
  • 1
    So, what does "registering my friends" mean in this context? In a client-server setup, one would be registering on the server... but what is the "user story" of the problem "register my friends (or other accounts)" in this context? Likewise, what is the story of trying to connect to another ip address? Why is a dynamic IP address a problem? –  Apr 04 '13 at 19:35
  • Dynamic ip seemed to me more difficult to serialize : as I suppose that the next time I want to use the stored adress, it may not be valid any more. Registering a friend is simply storing an id and a ip adress. – loloof64 Apr 04 '13 at 19:39
  • Could you put into the question the idea (the stories) of how this application starts up and what the steps one goes through while playing the game (and which of these you have difficulties with)? It would help in answering the question rather than going back and forth in comments. –  Apr 04 '13 at 19:47

1 Answers1

3

Instead of peer to peer, why not have a central server in which connections are handled and the server's responsibility is to connect the peers together. This also facilitates easier security, acquisition of IP Address and other information that could be kept for storage by the server.

A nice threaded-server in which each connection causes server to spawn a thread and connect that thread to another and thus set up peer to peer would be cool.

This virtualized peer to peer would be simpler and easier to manage in my opinion.

Mushy
  • 345
  • 1
  • 7
  • That sounds good to me : so you are saying that the PHP server manages both connections and games ? Ok. In fact Java seemed good to me as Threaded applications are simpler to write (among several other factors). And threads will be mandatory for time management. – loloof64 Apr 04 '13 at 20:14
  • `so you are saying that the PHP server manages both connections and games ?` No, separate the network connectivity from the game. Have separate classes handle the connectivity and the game itself. And +1 if you liked the answer (vote it up). – Mushy Apr 04 '13 at 20:25
  • Because you never know when "the man" is going to crack down on your illicit underground chess gang. Or you want your epic chess game to survive eons past the date when the original author pulls the plug on that ancient box in his closet. Or you're worried about corporate marketers harvesting your game data to facilitate their prying eyes getting into your privacy. – Philip Apr 04 '13 at 20:30