2

I have to connect a remote server via tcp socket from the Watch.

I have already written a piece of code using CFStream which works perfectly from the Watch simulator.

When I run it on the Watch I get this error:

The operation couldn’t be completed. Can't assign requested address (Code = 49)

when I try to open the connection to the server using CFStreamCreatePairWithSocketToHost.

The Apple documentation declares that CFStreamCreatePairWithSocketToHost is

Available in watchOS 2.0 and later.

so I expected that it had should work but I have found this Apple's engineer answer which confirms that there is no way to open a tcp connection from the Watch:

Socket communication does not work real Apple Watch

Can anyone clarify and help me to understand?

Supposing that I cannot open a tcp connection from the Watch, what kind of alternatives have I, since I cannot use [NSURLSession]?

I could use one of the communication methods provided by [WCSession] but do they work when the iPhone app either is not running or is not in foreground?

Fab
  • 1,468
  • 1
  • 16
  • 37

1 Answers1

1

You could use WCSession's sendMessage APIs to wake the iOS app up in the background and have it do the Stream work for you.

ccjensen
  • 4,578
  • 2
  • 23
  • 25
  • 1
    Yes, it's what I am already doing. It's awkward but it's actually working. As expected, speed and throughput are pretty low (both simulator and Watch) and I am struggling to heavy filtering not necessary messages. Thank for your suggestion. – Fab Oct 28 '15 at 06:17
  • I'm in the same condition... then I use the phone as bridge for TCP communication but the communication is very slow when the phone is in standby. – Lorenzo Oct 28 '15 at 12:13