I would like to implement an internet service from within a Cocoa
application such that when a remote client requests a connection on
a certain port the connection and subsequent service will be
handled by the Cocoa application.
I want to do this using Cocoa Foundation classes if possible, but
it's not really clear from the documentation how to set this up.
Most of the documentation is geared towards Distributed Objects
(DO) and not provision of a TCP port service in the classic Unix
I think you need to use Core Foundation for a listening socket.
CFSocket lets you create a socket that listens for incoming
connections in a run loop. You get a callback for each connection.
Check out http://developer.apple.com/samplecode/CFLocalServer/
index.html It is for UNIX domain sockets, but you can do the same for
Once you get a connection, you are passed a bsd-style file descriptor
in the accept callback. Pass that to CFStreamCreatePairWithSocket()
to get a CFReadStreamRef+CFWriteStreamRef pair. These are toll-free
bridged to NSInputStream and NSOutputStream.
The code below is a bit messy - it is part of a Ruby wrapper for
CFSocket. Apple's sample code is probably better.
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden