• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFSocket questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: CFSocket questions
      • From: Edward Fink <email@hidden>
References: 
 >Re: CFSocket questions (From: Edward Fink <email@hidden>)

  • Prev by Date: Re: OS X Socket Performance
  • Next by Date: CFSocket Callback
  • Previous by thread: Re: CFSocket questions
  • Next by thread: Re: CFSocket questions
  • Index(es):
    • Date
    • Thread