On an iPhone I have created a UDP socket and bound it to the WLAN interface. I enabled SO_BROADCAST and I am able to send broadcast packets to the network (confirmed by a client running on my notebook.) But the UDP socket on the iPhone is unable to receive broadcast packets.
In my opinion this is a kernel bug, because not allowing a socket with SO_BROADCAST enabled to receive any broadcast packet, is a bad design decision.
The problem is further described here and here. The most popular solution to this problem is to bind to INADDR_ANY. However, it would be nice to be able to bind an UDP socket to only one interface while still receiving broadcast packets! Is there really no way to achieve this?
(When I bind a socket to 192.168.1.7 on a class C net (/24), it should accept packets sent to 192.168.1.7 and packets sent to 192.168.1.255!)
Thanks!
pls check below link may be it's helpful.
Receive udp broadcast packets ios
iPhone UDP broadcast and response
iOS UDP broadcast vs. PHP UDP broadcast
https://github.com/robbiehanson/CocoaAsyncSocket
Related
I am trying to send the wifi direct probe packets using raw sockets so that mobile devices will show them in wifi direct device list.
I am trying to capture packets first in Wireshark in monitor mode in order to understand the packet structure and compare with the P2P probe request packet mentioned in Wifi Direct specification.
But I am not able to capture the correct probe packet in Wireshark. Can anyone suggest me what I am missing in my approach?
I wasn't able to capture packets with filter WLAN.addr= XX:XX:XX:XX:XX:XX. (Actual wifi Mac address), as WiFi Direct Mac address is different and the first byte was different.For example If your wifi mac is 00:04:CB:CX:DE:E7 then WiFi-Direct address is 02:04:CB:CX:DE:E7.
Also, I am able to show the device listed when I sent probe response packet to the device.
I have a basestation (beaglebone running linux) at my home which is connected to multiple cameras. I connect my iPhone iOS9 to the basestation via TCP and the basestation will stream the video of each camera to a specific UDP port. All is well.
I want to be able to see the cameras when I am not connected to the local network. When my phone is connected to LTE, I have the iPhone connecting to the public address of my router via TCP and with port forwarding, all data is forwarded to the basestation. I am connecting and talking just like it was on the local network with the TCP client. All is well.
The problem is when the video is streamed via UDP on a specific port, no different than when on the local network, the basestation has no problem sending the packets, but the iPhone is not receiving anything. I am using GCDASYNCUDPSOCKET and my cellular carrier is Verizon.
I am wondering if this issue is due to Verizon blocking UDP packets? Or possibly there needs to be something else done other than just binding the iPhone UDP socket to a specific port and calling the beginreceiving function. I feel if it works on the local network, it should work on the cellular network.
I have also tried to ping the address of my cellphone from my computer which does not work. I am guessing the reason is because the iPhone has blocked this. It should be no different than pinging the address of google or anything else.
Please give me some insight on the possible issues or work arounds. I don't think I need to port forward the UDP since it is only outgoing and my Netgear router does not limit any outbound traffic (from the router to the iPhone). I was doing all this TCP before trying to send the video via UDP. It is much slower waiting to receive acks for 5 cameras streaming live video. And when it doesn't receive a packet it backs up the buffer and causes more issues. Also I had an issue with the TCP packets combining together so then I had to implement some kind of custom ack which made the delay worse, or add an end of message, but then it slows down on parsing and since I don't know exactly what data is coming it made things more difficult.
UDP is the way to go, just cannot receive the packets at this time. My understanding is a lot of games use UDP and they work on LTE network, so I'm not quite sure what the problem is. Is there special UDP ports that only work with Verizon?
I am doing one demo for connecting iPhone to Windows PC for sending files and text to PC from iOS Device. Can anyone give me a solution how can I approach it?
You can start to study the socket connection. With a TCP connection you can send and receive data to / from PC.
Another way (to avoid the TCP connection) is to use UDP message: in this case you should write a UDP listener in your iOS App that listen incoming message on a specific udp port.
look at his link:
iPhone TCP/IP Socket Server/Client Program
Can iOS app listen to a socket to become a server of some kind? If yes, what are limitatoins? Can you connect to this server from outside of your iphone/ipad, can you connect to it from the webpage on the same iphone using the websockets?
Yes it can, to some extent. Check this topic:
UDP broadcast using CFSocket on IOS
What i was able to do was listen to packets sent on broadcast, or to my apps IP address. Then you can just make your own socket callback function that would react to received messages.
As to limitations of sockets and communication with other devices, most of it is described in Apple documentation.
Ideas:
1. Pinging all my subnet ( using simple ping etc )
2. Sending GET to all IP in my subnet? ( may be too slow) waiting for 200 or 404 reply.
Thanx
Can you program your ethernet device to respond to Bonjour (mDNS) requests? That's the preferred discovery mechanism in the OSX/iOS ecosystem. avahi is an open-source mDNS daemon you might be able to run if your device runs a UNIX-like OS. You might also be able to find or write an embeddable mDNS server that you could integrate into your server if you're not running an OS as such.
Otherwise, I'd probably go with a custom broadcast UDP packet that the device will respond to. (which is basically what Bonjour/mDNS does, but less general) To send a broadcast UDP packet, open a UDP (datagram) socket and send a packet to the local subnet's broadcast IP. Make the packet contents suitably unique, and get your device to respond, e.g. using an HMAC, to avoid picking up any other devices or daemons which coincidentally answer on the same port.
This is a pure IP networking question. What you want to do is to send a TCP/IP broadcast message to the network and have you custom device respond to it. See TCP/IP Guide for some basic details.