• 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: Implementing a TCP port listener in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Implementing a TCP port listener in Cocoa
      • From: Douglas Davidson <email@hidden>
References: 
 >Implementing a TCP port listener in Cocoa (From: Rick Hoge <email@hidden>)
 >Re: Implementing a TCP port listener in Cocoa (From: Jakob Olesen <email@hidden>)
 >Re: Implementing a TCP port listener in Cocoa (From: Andrew Bowman <email@hidden>)

  • Prev by Date: Re: How to debug during Unit Test (otest)
  • Next by Date: Re: Executing non objective-c code in a loaded bundle
  • Previous by thread: Re: Implementing a TCP port listener in Cocoa
  • Next by thread: Re: Implementing a TCP port listener in Cocoa
  • Index(es):
    • Date
    • Thread