I would like to write an iOS App using XCODE Swift 3 to test UDP communicate with a general TCP/UDP terminal testing program (which is an app installed in another cell phone). Considering all devices are in the same Wifi network, the UDP terminal testing program is listening to a port number 12333, and the iOS App will have a button showing on screen. Once the button is pressed, a UDP broadcast message is sent. This message should then be received and displayed on the UDP terminal testing program.
I found a link which describe UDP broadcast issue, but it was written in objective-C. Then I tried to modify the code using Swift 3, I failed in modifying the following two lines of codes.
// Problem: Swift 3 doesn't have the function "htons()"
"broadcastAddr.sin_port = htons(8585)"
// Problem: cannot convert value of type "sockaddr_in" to expected argument type "sockaddr"
ret = sendto(socketSD, request, strlen(request), 0, (struct sockaddr*)&broadcastAddr, sizeof(broadcastAddr));
Is there anybody can help on the issue? Or am I in the right direction in testing the UDP communication?