Re: UDP responses and listeners
Re: UDP responses and listeners
- Subject: Re: UDP responses and listeners
- From: Josh Graessley <email@hidden>
- Date: Mon, 26 Jul 2010 16:11:18 -0700
On Jul 26, 2010, at 3:57 PM, Jeff Davey wrote:
> Questions:
>
> 1) Is a listener appropriate to get a response from a UDP device? Device #2 specifically?
Normally a listener is a TCP socket waiting for TCP connection. When a new connection comes in, the listening socket indicates that it is ready for reading. The software would call accept on the listening socket to get the new socket representing the new connection.
UDP sockets are completely different. There is no connection. Once you have bound a socket to a given address/port as CFSocketSetAddress would seem to do, you can receive packets from any sender on that socket. With socket layer code, one would normally use recvfrom or recvmsg instead of recv to determine the remote sender of the data. There is no need for a listener socket that you only call accept on.
> 2) If a listener is appropriate, what callback type should I be using? Accept, connect, etc...
I think you're looking for kCFSocketDataCallBack. I'm not certain, but I think that may work with UDP sockets. If not, you'll probably want to use kCFSocketReadCallBack and then call recvfrom/recvmsg directly on the native socket to read the data.
> 3) Am I missing something?
Working code ;)
> 4) Am I close? In the right neighborhood?
I think you're very close.
-josh
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden