Re: Implementing a TCP port listener in Cocoa
Re: Implementing a TCP port listener in Cocoa
- Subject: Re: Implementing a TCP port listener in Cocoa
- From: Jakob Olesen <email@hidden>
- Date: Wed, 28 Jun 2006 23:58:20 +0200
On 28/06/2006, at 23.35, Andrew Bowman wrote:
On Jun 28, 2006, at 12:16 PM, Jakob Olesen wrote:
On 28/06/2006, at 16.06, Rick Hoge wrote:
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 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 INET sockets.
Is there something wrong with using NSSocketPort and asynchronous
callbacks with NSFileHandle? Assuming serverSocket and
serverHandle are instance variables, something like:
serverSocket = [[NSSocketPort alloc] initWithTCPPort:myPortNumber];
serverHandle = [[NSFileHandle alloc] initWithFileDescriptor:
[serverSocket socket] closeOnDealloc:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(acceptConnection:)
name:NSFileHandleConnectionAcceptedNotification object:serverHandle];
[serverHandle acceptConnectionInBackgroundAndNotify];
That looks reasonable. I wasn't aware of
acceptConnectionInBackgroundAndNotify.
_______________________________________________
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