• 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
In airplane mode, socket writes unexpectedly don't fail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

In airplane mode, socket writes unexpectedly don't fail


  • Subject: In airplane mode, socket writes unexpectedly don't fail
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 30 Oct 2018 16:40:30 -0700

A co-worker is struggling with handling online/offline transitions in some
networking code in a Xamarin (i.e. Mono, i.e. .NET) app for iOS. The code
maintains a TCP socket to a server. If the device goes offline or into Airplane
Mode, the code needs to close the socket, so that the higher levels of the app
know it’s not online anymore.

The behavior he’s reporting is that, when the device is put into Airplane Mode,
the socket acts as though it’s still connected. It doesn’t close, and
(obviously) doesn’t receive any data, but most strangely the socket doesn’t
fail after data is written to it. My knowledge of TCP tells me that if you
write to a socket, but no ACK packet is received within ~15 seconds, the socket
will be closed with an error (I think ECONNRESET?) But he swears this isn’t
happening — it’s like the writes go to /dev/null.

I’ve never seen this, but I’ve mostly been using NSURLSession or at least
NSStream, not POSIX socket APIs, so the behavior may be different. My first
guess was that Mono is doing something sketchy; he looked into the source code
and found that it uses send() instead of write() to write to the TCP socket; is
that kosher?

The workaround he’s adopting is to run a SCNetworkReachability notifier, and to
close the socket and go into offline mode when notified that the host is
unreachable. I’m uncomfortable with this, since I know Reachability can be
unreliable and this usage doesn’t go along with the best practices, i.e. using
it just as a trigger to connect, not disconnect.

So what’s the deal with Airplane Mode? I would assume that it takes down all
network interfaces, which would close all sockets. But it doesn’t. Even so, I
would assume that writing to a TCP socket would cause an error pretty soon; but
apparently it doesn’t.

Any advice?

—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: In airplane mode, socket writes unexpectedly don't fail
      • From: email@hidden
    • Re: In airplane mode, socket writes unexpectedly don't fail
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
    • Re: In airplane mode, socket writes unexpectedly don't fail
      • From: Mike Dolan <email@hidden>
  • Prev by Date: Re: WebDownloadDelegate delegate methods called on non-main thread
  • Next by Date: Re: In airplane mode, socket writes unexpectedly don't fail
  • Previous by thread: Re: WebDownloadDelegate delegate methods called on non-main thread
  • Next by thread: Re: In airplane mode, socket writes unexpectedly don't fail
  • Index(es):
    • Date
    • Thread