Re: CFSocket questions
Re: CFSocket questions
- Subject: Re: CFSocket questions
- From: Douglas Davidson <email@hidden>
- Date: Mon, 9 Sep 2002 09:36:24 -0700
On Friday, September 6, 2002, at 09:19 PM, Edward Fink wrote:
The function(whatToDo) which gets executed when data arrives on the
socket....can this also be a method within a class? If so...what
would that look like. The reason I ask this is because I am having a
problem conceptually figuring out how I would actually be able to make
more than one connection via CFSocket if each different socket is
going to reference the same function. So if I had a function which
was responsible for creating and connecting a CFSocket and the
function "whatToDo" which handled the callbacks....how would I
differentiate the data arriving? Meaning if I had 3 sockets connected
to 3 different servers....and all their data is getting handled by
function "whatToDo"...how am I to know what data has just arrived from
which server? Will I need to create an array holding all my sockets
so I know which server, etc?
This is what the context is for. The context in CFSocket (and a number
of other CF types) is a way for you to add an arbitrary pointer to let
you distinguish different instances of the same type. It's something
like the userData in some Cocoa classes, but if you want you can hook
it up to be more like a delegate.
For example: when you create the CFSocket, you can pass it a
CFSocketContext whose info is a pointer to the object you want to pair
with this particular socket. If you want the CFSocket to retain that
object, then you can set the retain and release pointers; otherwise you
can leave them NULL. When you get a callback, the last argument to the
callback function is that info pointer. Cast it to the type of the
object you are using, and then you can send messages to it. The second
argument to your callback tells you what type of callback you are
getting (data, connect, accept, etc.) which might tell you what message
to send.
Douglas Davidson
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.