How to distinguish among nodes running on a same machine in a p2p network, socket in language C -


I want to create a full network (each node connects to the remaining nodes). There is a group of my colleagues who say that it includes P2P1, P2P2, P2P3 Assuming that all colleagues are running on the same machine (localhost), each colleague has a client side and server side that is written in the same file.

The first P2P1 has been started as a "P2P name_off_group port_number_furrest_side". Then P2P2 is called "P2P name_off_greative port_number_forcerside port_number_off_p2p1". And then P2P3 is called "P2P name_off_great port_number_p_verver_side port_number_off_p2p2".

P2P2's client side connects to server side of P2P1, connects P2P3's client side to server side P2P2.

Now P2P1 connects to P2P3 (Automatically in code, not user). If there is a new coworker, say that P2P4, also would like to connect with P2P1 (by the user). How can I distinguish between P2P3 between a old coworker and P2P4 as a new counterpart, because the two have only connected P2P1 (not yet sent) for the first time .

In addition, I considered to use "hostname: port" to differentiate them, but since they are running on the same machine (hostname is the same), and port client port (The server port is not unique to every coworker, there are many client ports in each peer) when P2P2 connects to P2P1, then P2P1 is informed that the P2P2 group (P 2 P1 and P2 P2). When P2P3 connects to P2P2, then P2P2 is informed that P2P3 has joined the group. However, the name of P2P2 in P2P1 differs from P2P2 on P2P2 because connecting P2P2 to client port from P2P1 is different from connecting P2P2 to P2P3. I want a unique name for P2P2, how can I do this? Thank you so much for your comment.

Honestly you lost me in your nomination plan.

I should give the question again.

  Does a server accept two connections? Is there a way to tell whether both connections are being started by the same agent?   

If this is the question you want to reply to, then the answer is not the only thing on the server at that moment that has been returned by the getpeername Which does not recognize the agent connecting your things in the plan.

You can consider specifying each agent to add a different category of client port or a handshake step to your protocol.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -