Closed lolriven closed 2 years ago
@JadeVand Did you find an answer to your question? If so, please don't leave this issue behind on the internet without the answer.
@bjorn Yes and no. I've realised that the issue is with my own machine, not the library itself. This exact code seems to work for other people when I give it to them to test but it will not work for me. And I believe it has something to do with how my machine handles loopback and broadcast. The question posed above is technically incorrect, because whether it works or not I believe is machine dependant not library dependant.
@JadeVand Hmm, that might be, but now that I read the documentation, I think you're using ENET_HOST_BROADCAST
wrong:
The constant
ENET_HOST_BROADCAST
may be used to specify the broadcast address (255.255.255.255). This makes sense forenet_host_connect
, but not forenet_host_create
. Once a server responds to a broadcast, the address is updated fromENET_HOST_BROADCAST
to the server's actual IP address.
So, you should first create a server on the LAN, usually just using ENET_HOST_ANY
, but in some cases you may need to be more specific about the network interface. Then, any client can use ENET_HOST_BROADCAST
when using enet_host_connect
to connect to any server on the LAN.
Then, when the server wants to send a message to all connected clients, it would call enet_host_broadcast
.
@bjorn I did end up trying that, setting my own address to ENET_HOST_ANY then trying different broadcast address for the client/connection. it was something I tested extensively for two days , using different broadcast IP addresses but I think it's as you mentioned I need "to be more specific about the network interface" because I was not able to get a broadcast on my machine.
From what I understand the function ENet_host_broadcast is either A: supposed to broadcast a message to all peers or B: broadcast a message to LAN. This part is ambiguous from what I can find on the internet.
When I try creating a host on ENET_HOST_BROADCAST the call fails
I also tried using enet_address_set_host and that too failed on the call to enet_host_create. I could create a host on ENET_HOST_ANY and have the peer manually enter the IP and Port but that would be a lot of effort. What steps do I take to broadcast a message to all peers on the LAN ?