We are having trouble receiving UDP multicast packets sent by a server every half a second. We are receiving with an IOS app, connected to the server directly via wifi, and we are using the CocoaAsyncSocket library to join the multicast group. Multicast packets are sent to destination port 12347 and the multicast group address is 225.0.0.37. We are certain that:
a) The rest of the app logic does not interfere to create the problem, i.e. an ios app with just the multicast logic connecting to the server is still problematic.
b) Other swift networking libraries with similar functionality did not solve the issue.
c) Other users have tried the exact same code we are using for their multicast connections successfully.
d) The UDP packets multicast by the server can be received by other apps. We have tried the android version of the same app which can successfully receive the packets, and we have used Wireshark (network packet sniffer) which also senses the UDP packets. We have not tried to receive the packets with a similar IOS app that would work in these circumstances because we couldn't find such an app.
e) We have noticed one specific sequence of steps we can take to successfully receive packets. That is, if:
1) We are connected to a different network upon launching the app.
2) We then navigate to the screen that opens the multicast socket.
3) Without closing the app (just pressing the home button) go to the wifi settings and switch to the server network.
4) Navigate back to the opened app.
This leads us to believe that for some reason we can only receive multicast UDP packets if the server wifi network is joined after the socket is opened.
Here is the code used for the UDP socket:
override func viewDidLoad() {
super.viewDidLoad()
let socket = GCDAsyncUdpSocket(delegate: self, delegateQueue:DispatchQueue.main)
do {try socket.bind(toPort: 12347)} catch {print(error.localizedDescription)}
do {try socket.enableBroadcast(true)} catch {print(error.localizedDescription)}
do {try socket.joinMulticastGroup("225.0.0.37")} catch { print(error.localizedDescription) }
do {try socket.beginReceiving()} catch {print(error.localizedDescription)}
}
func udpSocket(_ sock: GCDAsyncUdpSocket, didReceive data: Data, fromAddress address: Data, withFilterContext filterContext: Any?) {
//this does not get called
print(data.description)
}
It is worth noting that we have tried both with and without the enableBroadcast command, it did not make any difference. Also, none of the catch statements are hit.
Here is the packet information captured by wireshark:
https://imagizer.imageshack.com/img924/7397/fAXebI.png
Any idea on what might be causing this?