UDPBroadcastConnection icon indicating copy to clipboard operation
UDPBroadcastConnection copied to clipboard

UDP broadcast doesn't work with iOS 14

Open konrei opened this issue 4 years ago • 9 comments

When trying to send data to all available devices using udp broadcast, it gives me this log message: “Error: sendingMessageFailed(code: 22)\n”] “Closing UDP socket”]

konrei avatar Oct 14 '20 11:10 konrei

I updated the library. Could you please check if the issue still persists? For me it always worked with iOS 14.

gunterhager avatar Jan 08 '21 07:01 gunterhager

This should help : https://developer.apple.com/forums/thread/662082

kenji21 avatar Jan 25 '21 07:01 kenji21

I experience also the similar issue on iOS 14 devices however already on binding:

let isBound = bind(newSocket, &saddr, socklen_t(MemoryLayout<sockaddr_in>.size))

this value is "almost" always -1 on iPad, however it works almost always on iPhone... Both devices are running iOS 14.4/iPadOS 14.4

igoMobile avatar Feb 09 '21 16:02 igoMobile

Can you try to add the NSLocalNetworkUsageDescription key to your Info.plist and tell us if it makes a difference ?

kenji21 avatar Feb 10 '21 05:02 kenji21

Yes, I tried it already, unfortunately there is no difference. By the way, thanks for the link above. There are some other suggestions how to realize the UDP connections, especially using bonjour. But in our case we have app implementations for Windows and Android and need to broadcast "pure" UDP messages through the network. I've contacted Apple support because of Multicast networking entitlement and am waiting for the reply... I'm almost sure, that I do not need, because the Implementation of Gunter works still on iPhone, only iPad experiences issues...

igoMobile avatar Feb 10 '21 10:02 igoMobile

Oh, I remember what I've done to have two iPad communicates fine : just send one packet (and you'll see the system alert about local network access)

kenji21 avatar Feb 10 '21 10:02 kenji21

hm, for sending a package I need a socket, but the binding fails with -1:

let isBound = bind(newSocket, &saddr, socklen_t(MemoryLayout<sockaddr_in>.size))

or do I misunderstand something? Thank for your previous prompt reply ;-)

igoMobile avatar Feb 10 '21 10:02 igoMobile

hey guys, thanks for your help. It turned out, that my problem was port 15000... after changing the port, it started working! after rebooting the ipad port 15000 got also released and i can use it again.

igoMobile avatar Feb 10 '21 15:02 igoMobile

Nice catch, maybe an indication about changing port in the debugPrint and in comment of ConnectionError.bindSocketFailed should help next users having this issue

https://github.com/gunterhager/UDPBroadcastConnection/blob/master/UDPBroadcast/UDPBroadcastConnection.swift#L173

https://github.com/gunterhager/UDPBroadcastConnection/blob/2303b9178f2cdb35e61edbeacbb0f9df437c1266/UDPBroadcast/UDPBroadcastConnectionError.swift#L18

kenji21 avatar Feb 11 '21 05:02 kenji21