britzl / defnet

Defold networking examples
MIT License
65 stars 16 forks source link

Change request: 1. multiple hosts discoverable, 2. provide individual host info on discovery #8

Closed lharder closed 3 years ago

lharder commented 3 years ago

Hi Britzl,

I have used your defnet library to discover hosts in a given network. It turned out that for me, the typical usecase was a little different, so I use some changes in a fork of your code. If you feel that they are useful, I would be glad if you considered them for the defnet upstream version:

  1. If I am not mistaken, you stop the discovering process after detecting the first remote host. I would prefer to allow for more than just a single host to communicate with the player. With the callback function, the application can stop the discovery process at any time it sees fit, but this change allows for finding more than one peer if needed.

  2. When searching for peers, you send a string to identify the type of host you wish to discover. Typically, to me, that would be the name/id of the game. However, I find it useful for every peer to be able to include some unique data, as well (e.g. each player's individual callsign). So instead of a test for equality of the id/name string, it is more flexible to check if the transmitted string only starts with the right string. That way, it can contain additional data that can then be evaluated by the application in the callback method.

To me, these trivial changes have been very helpful. Please let me know what you think.

Regards, Lutz

p2p_discovery.lua.zip

britzl commented 3 years ago

Great suggestions! Thank you. I've included both of them and will do a new release.

britzl commented 3 years ago

By the way: Why not strip away the initial part of the string and only return the additional data? The client would have to do that otherwise right?

lharder commented 3 years ago

Yes, you are right - by all means :o) I have added that line of code:

p2p_discovery.lua.zip

britzl commented 3 years ago

Great, thanks!