Godot Version
v4.6.1.stable.official.14d19694e
Question
Hi! I am currently developing LAN broadcast, IPv4 was simple and works perfectly, but when trying to support IPv6, it is weird. The code below works, but it would send the packet using weird interfaces, such as localhost on Windows and dummy0 on Android, despite Wi-Fi and other interfaces being available, which is not good, because the only device that then discovers that packet is the device which sent it. Is there a way to choose which interface sends the IPv6 packet, or something that would fix my situation? IPv4 broadcast is good enough for my project, but I am curious if its possible.
# SERVER
var peer := PacketPeerUDP.new()
peer.set_dest_address("ff12::6435", 40256)
peer.put_packet("Hi! Join me on port xxxx".to_utf8_buffer())
# CLIENT
var peer := PacketPeerUDP.new()
peer.bind(40256, "*")
# The following line is called on every interface
peer.join_multicast_group("ff12::6435", "wlan0")
peer.join_multicast_group("ff12::6435", "lo")
# When a packet is available
var packet: PackedByteArray = peer.get_packet()
var ip: String = peer.get_packet_ip()
Example Console output from Windows:
New packet from fe80:0:0:0:f474:f79c:4bb8:baf1 (PORT 52761)
Where fe80:0:0:0:f474:f79c:4bb8:baf1 is the Wi-Fi interface, which is weird, because just a second ago, without changing the code it would output ::1, but on Android it still outputs the ip from dummy0. (This is the first time I was able to recieve the signal from another device, as of writing this post)
Another question, do I have to be using diffrent PacketPeerUDP for IPv4 and IPv6 (for recieving)?
Also, a MULTICAST_LOCK is aquired on Android, which works, because IPv4 broadcast works fine (without it not):
# The reference to this Object is never lost
static var _android_fix: Object = null
func get_lock() -> bool:
var android_runtime: JNISingleton = Engine.get_singleton("AndroidRuntime")
if android_runtime == null:
printerr("Android MulticastLock: AndroidRuntime not available")
return false
var activity: Object = android_runtime.call("getActivity")
if activity == null:
printerr("Android MulticastLock: No Android activity")
return false
var wifi_service: Object = activity.call("getSystemService", "wifi")
if wifi_service == null:
printerr("Android MulticastLock: No Wi-Fi service")
return false
_android_fix = wifi_service.call("createMulticastLock", "godot_multicast_lock")
if _android_fix == null:
return false
return true