UDP broadcasting

Hello,
I made UDP peer to peer program which chck if anybody is broadcasting, if yes then he connects to broadcaster, else he starts broadcasting itself. When boths peers are connected then they are sending position of cursor to other peer. It works perfect when program is running at my mobile first and then on my computer. But when I do it conversely then both of peers are broadcasting but they don’t connects to each other.
I’m not using DefNet, only LuaSocket, becouse I want to understand how it works.
Does anybody know where the error could be?

What do you mean by “connected”? UDP is connectionless protocol.

From my point of view, you should use debugging tools like Wireshark. Otherwise, it is a hard task to debug such things.

1 Like

Thank you very much for your reply. I’m sorry, that’s true, I meant to set setpeername to the ip address of the other object.

I’ve already downloaded Wireshark to see if the information is being sent correctly, but I don’t understand how I can use it for debugging.

1 Like

Get wireshark to watch your ethernet/wifi adaper… then in the filter panel you can reduce the traffic to just those packets you want to see… Then you can see perhaps why its working or not
e.g ip.addr == 192.0.2.1 to filter just packets related to this address
ip.src == 192.168.1.1 filter to packets where this ip is the source
udp.port == 120 filter udp packets with this port. If your game uses a specific port this could be handy.
If you have something specific in the packet to search on you can do…
frame contains “bbc”
which will show packets with that keyword in.

The search bar is top.
Pack rows are shown beneath… when you click on a packet… the bottom of the screen shows the packet data… you can learn a lot just double clicking and examining things in Wireshark.

1 Like

Thank you very much, I did it as you wrote, but it seems that the data is leaving without problems from the computer and the mobile phone.

Did you ever resolve this, as I am encountering the same issue?

I am using britzl’s defnet plugin, and to begin with it worked fine.

I have my project running in Defold’s simulator on my Mac, and press a button to make it call self.p2p.broadcast(“mymessage”) to make it discoverable.
On my phone I have the exact same project running, but press a different button to make it listen for the “mymessage” broadcast in order to find the IP address of the host.

For a few days it worked as expected, and I used the discovered p2p address to establish a TCP connection. Yesterday, it stopped working for no obvious reason.

Using wireshark seems to suggest that my Mac is sending the UDP messages out, but they are no longer picked up on the phone. My initial thought was “I must have changed something in the project without realising”, however that does not appear to be the case. If I perform the operations the other way around so that the phone is the host and the simulator on the Mac is the client, everything works as expected.

I’ll be the first to admit that I don’t know much about internet protocols, so could it be related to the port being used? Or that the default behaviour of the p2p_discovery module is to broadcast to 255.255.255.255:
broadcaster:sendto(message, "255.255.255.255", port)

If either case is true why would it have worked a few days ago, still work in one direction, but not work in the other?