truvorskameikin / udp-discovery-cpp

A small library to add local network discovery feature to your C++ programs with no dependencies
MIT License
60 stars 28 forks source link

Support multiple instance of application per host #8

Closed G10h4ck closed 5 years ago

G10h4ck commented 5 years ago

Right now if I start two instance of the same application on the same host, it seems that udp-discovery-cpp will see only one of them, at first it seems this happens because because the same socket is used both for listening and sending packets, so the source port is de same as destination port and is the same for all instances, thus as IP:Port is used as identifier for endpoint, seems there is no way to have multiple different endpoints on same host.

This probably can be easily solved using a different socket to send the packets so the source port can be random, and automatically the different endpoints should be recognized.

truvorskameikin commented 5 years ago

Can you provide your endpoints configuration?

I have started discovery_example in discover mode and two instances of discovery_example in discoverable mode. I was able to see two discovered endpoints.

I have updated discovery_example tool to show not only ip of discovered endpoint but also port.

G10h4ck commented 5 years ago

I run 3 instances in 3 different shells on my laptop with this ./udp-discovery-example both ciaone1 each of them with different used data, then each of them display just one discovered endpoint all in the same port

Shell 1:

$ ./udp-discovery-example both ciaone1
Discovered endpoints: 1
 - 10.1.155.69:12021, ciaone2

Shell 2:

$ ./udp-discovery-example both ciaone2
Discovered endpoints: 1
 - 10.1.155.69:12021, ciaone1

Shell 3:

$ ./udp-discovery-example both ciaone3
Discovered endpoints: 1
 - 10.1.155.69:12021, ciaone1

Probably the problem arises only in both mode because the socket used to discover get the same source port and destination port because it get bonded

truvorskameikin commented 5 years ago

Please review #9.

truvorskameikin commented 5 years ago

Resolved in #9.