• 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
Socket detecting disconnect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Socket detecting disconnect?


  • Subject: Socket detecting disconnect?
  • From: Rachel Blackman <email@hidden>
  • Date: Sun, 19 Mar 2006 20:10:20 -0800

I recognize that BSD sockets are a BSD subsystem thing, but as there's no direct Cocoa equivalent and everyone seems to wrap BSD sockets (or CFSocket around BSD sockets) into Cocoa, I'm going to ask here. :)

Socket stuff works pretty well in my Cocoa app, save for one problem. I need to have a continuous TCP connection to a remote host, and (as anyone who's dealt with NAT will know), when a connection goes quiet for long amounts of time a NAT router will sometimes silently drop it. Annoying!

Usually, under any other system I've worked with, you detect this as soon as you attempt to send data again and write() errors out; it's just part of life behind NAT, sometimes your stream gets disconnected unless you have some kind of ping method. People are used to this, and so you type something random and see the 'disconnected' and go 'Ah, well, there we go.'

But on OS X, it seems that write() never errors out. Your connection can be gone entirely, completely dead, and write() happily returns that it has sent the entire buffer. This, to put it bluntly, Annoys Me. (Or more specifically, it annoys my NAT-using users, who find themselves silently disconnected and don't even know when it happened.)

I don't have a NAT router on my network, but for testing purposes I've yanked the cable out of my computer and find the write() still happily returning that it has written the entire buffer, apparently oblivious to the fact that my entire network has gone away. (I realize that in this case I could use SCNetwork to detect the cable being gone, but that doesn't solve the original NAT problem; in that case, the connection has gone away silently, not the network.)

Surely I'm not the only person to run into this problem (in fact, a quick Google shows I'm definitely not), but poking and prodding around via Google et al has not yet produced any answer as to how to solve it. I know there /does/ have to be a solution, since there are some things out there which can detect such a disconnect.

I'm just really bewildered why OS X's write() behaves differently than, well, every other write() I've ever encountered, and if anyone knows how to work around this behavioral difference. It's doubly annoying because the man page for write on OS X mentions nothing about this.

Help me, Obi-Wan Cocoanobi, you're my only hope!  Or something. :)

--
Rachel 'Sparks' Blackman -- sysadmin, developer, mad scientist
"If it is not broken, give me five minutes to redesign it!"

_______________________________________________
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: Socket detecting disconnect?
      • From: Greg Herlihy <email@hidden>
  • Prev by Date: Re: NSString propertyList crash
  • Next by Date: How to Display Simplified Print Panel
  • Previous by thread: Second Window Leak
  • Next by thread: Re: Socket detecting disconnect?
  • Index(es):
    • Date
    • Thread