I really did try to keep this short. I've been reading and researching
this for over a week and I want to be clear...
Using Xcode 3.2.2
Testing on iPhone Simulator 3.2 (193.8)
Using WireShark to view UDP traffic
I'm writing an iPad app that communicates with two different devices.
The first device has a defined port to send data to (2638). The second
device has two defined ports. One to send to (21075), and a port that
responses are sent back to (21076). All sockets are added to the run
loop
When I send data to the first device, it sends a response back based on
the source address and port of the send command.
SEND
(source) (destination)
-------------------------------------
iPad port --> Device A port
52526 --> 2638
192.168.1.100 --> 192.168.1.200
RECEIVE
(destination) (source)
-------------------------------------
iPad port <-- Device A port
52526 <-- 2638
192.168.1.100 <-- 192.168.1.200
Here is my call to CFSocketCreate:
sock_send_dev_one = CFSocketCreate( kCFAllocatorDefault,
PF_INET,
SOCK_DGRAM,
IPPROTO_UDP,
kCFSocketDataCallBack,
DeviceOneCallback,
&ctxt);
This works great. I send a command, the device sends a reply. My
callback gets called and I pull the response out of "const void * data".
I've used WireShark to look at the packets going back and forth.
Everything looks good.
*****************************
The second device is a little different. This device has a send port
and a receive port. This device sends a reply back to an explicit port
and broadcasts it to the network. (also confirmed with WireShark)
SEND
(source) (destination)
------------------------------------------
iPad port --> Device B port
55834 --> 21075
192.168.1.100 --> 192.168.1.200
RECEIVE
(destination) (source)
------------------------------------------
iPad port <-- Device B port
21076 <-- 49442
255.255.255.255 <-- 192.168.1.200
I've set up two sockets for this device
The SEND socket is created using this statement:
sock_send_dev_two = CFSocketCreate( kCFAllocatorDefault,
PF_INET,
SOCK_DGRAM,
IPPROTO_UDP,
CFSocketNoCallBack,
NULL,
NULL);
The LISTEN socket is created using this statement:
sock_listen_dev_two = CFSocketCreate( kCFAllocatorDefault,
PF_INET,
SOCK_DGRAM,
IPPROTO_UDP,
CFSocketAcceptCallBack,
DeviceTwoCallBack,
&ctxt);
I then call:
CFSocketError err = CFSocketSetAddress(sock_listen_dev_two,
m_addr_sig_listen_dev_two);
to listen...
The send socket works fine. I send commands to this device and it is
operating appropriately. I tell it to play a video, it plays the
correct video. I tell it to pause it pauses, etc...
The creation of the listen socket seems to be successful. No errors
reported in my code, but my callback is never called.
Before running the app, there is no entry for 21076 in lsof
While running the app, there is an entry for 21076 in lsof
*****************************
Questions:
1) Is a listener appropriate to get a response from a UDP device?
Device #2 specifically?
2) If a listener is appropriate, what callback type should I be using?
Accept, connect, etc...
3) Am I missing something?
4) Am I close? In the right neighborhood?
Thanks in advance for any advice or a nudge in the right direction.
~jeff
--
"Character is who you are when no one is watching."
|