• 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: Reconnecting to a NetService after a stream error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reconnecting to a NetService after a stream error


  • Subject: Re: Reconnecting to a NetService after a stream error
  • From: Marc Krochmal <email@hidden>
  • Date: Wed, 03 May 2017 10:20:06 -0700



On May 3, 2017, at 9:38 AM, Jeff Kelley <email@hidden> wrote:

Hi all,

I’m writing an app that begins a NetService on tvOS and connects to it from iOS. I’m creating the service with a port number of 0 to get an automatic port and publishing with the .listenForConnections option. On the client (iOS) side, once I resolve an address for the service I use its getInputStream(_:outputStream:) method to get input and output streams set up. I create a background thread to handle callbacks on and schedule the streams on its RunLoop.

What I’m noticing is that I get a lot of stream errors with this setup. I’m using JSONSerialization to write JSON objects to the stream and for the most part it works, but when I get these errors I’d like to reconnect. It seems like I can’t just call getInputStream(_:outputStream:) again on the resolved service, as doing so gives me all kinds of errors about a socket not being available. My next thing to try will be to rediscover the service, using its TXT data to make sure it’s the same one, re-resolve the address, and try again.

I’m pretty new to Bonjour and there aren’t a whole lot of resources out there for how to handle stream errors. Am I on the right track? What kind of gotchas should I be aware of here (for instance, is there a hard number of clients that could conceivably connect to a NetService on an Apple TV)?

Hi Jeff, I'm not sure why you're getting stream errors but after the failure you might try creating a fresh copy of the NSNetService and then try grabbing new streams from that.

-Marc



Thanks in advance for any pointers!


Jeff Kelley

email@hidden | @SlaunchaMan | jeffkelley.org

(Cross-posted from cocoa-dev, sorry for the noise to those who get this twice!)
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: Reconnecting to a NetService after a stream error
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Next by Date: Re: Reconnecting to a NetService after a stream error
  • Next by thread: Re: Reconnecting to a NetService after a stream error
  • Index(es):
    • Date
    • Thread