This discussion is archived
2 Replies Latest reply: Nov 30, 2012 7:43 AM by 977248 RSS

Server/Client -> Client/Client

807956 Newbie
Currently Being Moderated
Dear all,

I want to set-up a peer to peer connection between some computers, so users can chat external Server. My first thoughts were as follows:

I make a central ServerSocket on a server, where all applications can connect to. This ServerSocket keeps track of the connected sockets (clients), and gives the IP and Port of a new connected client to all other clients.
Each client creates a new ServerSocket to which all clients can connect to. ( [http://img837.imageshack.us/img837/4659/examplefe.png] )

In other words: every client has a ServerSocket with all other clients connected to it. The messages should go via the blue lines in the images.

There is just one little problem I run on: if I test this via all different IP addresses, it works fine, but when two clients have the same (extern) IP-adress, it will not work anymore. Does someone know a smart solution for this?

Thanks! Marc
  • 1. Re: Server/Client -> Client/Client
    DrClap Expert
    Currently Being Moderated
    So presumably your central server is using the IP address of the client to tell the other client where to connect to.

    Or perhaps you have the port number for the client's ServerSocket hard-coded, and the second client on a machine can't start its ServerSocket.

    I'm just guessing because all you said was "doesn't work".

    Anyway what I would suggest is that the clients should choose from a range of port numbers to create their ServerSocket; keep trying different ports until one works. And then the client should communicate both their IP address and port number to the central server to notify it that the client is available to chat. And finally the server should send the client's IP address and port number to another client who wants to chat with it.
  • 2. Re: Server/Client -> Client/Client
    977248 Newbie
    Currently Being Moderated
    I think the problem is on the network.

    You doesn't need to confuse about the codes in Java. To avoid ip conflict you just need to use dynamic ip addressing scheme on your clients.

    Install DHCP server on your central ServerSocket.
    Remove your static ip addressing option on the clients.
    Start the DHCP server and reload network configuration on the clients.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points