Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 ?

share|improve this question
    
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? –  MichaelT Apr 4 '13 at 19:32
    
I want to code a peer to peer application. –  Laurent BERNABE Apr 4 '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? –  MichaelT Apr 4 '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. –  Laurent BERNABE Apr 4 '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. –  MichaelT Apr 4 '13 at 19:47

1 Answer 1

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.

share|improve this answer
    
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. –  Laurent BERNABE Apr 4 '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 4 '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 4 '13 at 20:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.