3 Replies - 20818 Views - Last Post: 14 October 2008 - 12:38 AM Rate Topic: -----

#1 boro84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-October 08

Peer to peer socket programming

Post icon  Posted 13 October 2008 - 09:04 AM

Hi,

I am making a simple 4 player online game which I had implemented using a client-server architecture.

Right now, I would like to convert it into a peer-to-peer architecture but I am not quite sure how to start.

Do I need to write the server code inside the client, and let the 1st client who connects be the server? Or is there a true peer-to-peer implementation.

Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Peer to peer socket programming

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Peer to peer socket programming

Posted 13 October 2008 - 11:57 AM

In a peer 2 peer architecture, both (all) hosts act as both client and server.
If you use TCP you'll have to create n*(n-1) serversockets and equally many clientsockets (assuming n hosts).
If you use UDP you only need 1 socket for each host but instead you have to handle all traffic on your own since it's not a reliable connection. It's pretty much flawless on a LAN though. However, you need to send data like who is it from and who is the reciever and so on.
You have to decide which suites you better.
Was This Post Helpful? 1
  • +
  • -

#3 boro84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-October 08

Re: Peer to peer socket programming

Posted 13 October 2008 - 10:10 PM

Hi Gloin,

Thnx for the reply. I got the idea already.

Another question. I should be using TCP. All of the 4 clients(1 player and 3 bots) will be connected using localhost. When creating the serversockets, each of the clients need to listen to different ports if I'm not wrong.

However, all of the clients are running the same application. How do I make sure that all of them listen to different ports? I need a server for that?

Also, I believe each client have to create 4 seperate threads for each of the players?

Regards.

This post has been edited by boro84: 13 October 2008 - 10:22 PM

Was This Post Helpful? 0
  • +
  • -

#4 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Peer to peer socket programming

Posted 14 October 2008 - 12:38 AM

I believe you can leave the port option blank and it will be taken care of by the method itself. Otherwise you can either hard-code it or use a loop that searches for available ports within some range [1024..65535]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1