Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client - client communication without server?

I am new to socket programming and I need to clarify some things.

Do you need a server between two client communication? Let me explain what I mean:

Example 1:

  1. Client1: Server, I want to talk with a client2
  2. Server: No problem. Let's just wait until he sends the request to connect
  3. Client2: I'm here. I want to talk with client1.
  4. Server: Okay Client1 here is Client2 IP address. And for you Client2, here is

Client1 IP Address. You can now talk to each other without me.

Example 2:

  1. Client1: Server, please send client2 a message: "Hey client2. How are you?"
  2. Server: Okay no problem. Sending message to client2
  3. Client2: Server thanks for sending client1's message. Send him a reply: "Hey, I'm fine."
  4. Server: Sending message to client1..

So my question is: Do you need a server after you met two clients together to communicate between them? Or I'm on completely wrong track?

EDIT:

The purpose behind this is that I want to expand my very simple mobile game to become a multiplayer. Just for example, I want to show PACMAN2 on PACMAN1 mobile phone and vice versa.

like image 866
rootpanthera Avatar asked Oct 31 '22 19:10

rootpanthera


2 Answers

If you are using a TCP socket programming, you need central server to facilitate communication between clients.

Reason - You cannot connect to a port on one client from every other client. All clients can connect to one server on a particular port and server can facilitate the communication among clients.

If you move away from socket programming and use advanced features like Messaging; peer to peer communication and broadcasting of messages to multiple clients can be achieved.

EDIT:

Still I prefer TCP over UDP for these reasons especially Reliability

In your case of multi player games, still your clients need to be connected to server on dedicated socket. Since you have to use TCP anyway, server can take care of sending messages between clients with client id.

like image 152
Ravindra babu Avatar answered Nov 02 '22 09:11

Ravindra babu


yes, you can do with peer to peer communication does not need any central server or you can also use sockect or you can communicate with user ip address.

Ref peer to peer

like image 23
ßãlãjî Avatar answered Nov 02 '22 11:11

ßãlãjî