Send data stream from WatchKit

For a project I am doing on Apple Watch, I am looking for a way to send streams of data to a server on a local network. It's fast online data, so I preferred it to be sent over UDP (but that wasn't a strict requirement for me). The data is the current accelerometer reading on the watch, which is taken every fraction of a second.

I am using WatchOS 2 (Beta 4), iOS 9 (Beta 4) (and latest Xcode 7 beta).

I used the following code:

- (void) sendMsg: (NSString *)msg{
    int socketSD = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (socketSD <= 0) {
        NSLog(@"Error: Could not open socket.");

    // set socket options enable broadcast
    int broadcastEnable = 1;
    int ret = setsockopt(socketSD, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
    if (ret) {
        NSLog(@"Error: Could not open set socket to broadcast mode");

    // Configure the port and ip we want to send to
    struct sockaddr_in broadcastAddr;
    memset(&broadcastAddr, 0, sizeof(broadcastAddr));
    broadcastAddr.sin_family = AF_INET;
    inet_pton(AF_INET, SERVER_IP, &broadcastAddr.sin_addr);
    broadcastAddr.sin_port = htons(SERVER_PORT);

    char *request = "Message from Watch";
    ret = sendto(socketSD, request, strlen(request), 0, (struct sockaddr*)&broadcastAddr, sizeof(broadcastAddr));
    if (ret < 0) {
        NSLog(@"Error: Could not open send broadcast.");
- (IBAction)watchGoButtonTouched {
    [self sendMsg:@"Hi"];


That manages to get a message on the server in the Watch simulator, but when it ran on the actual watch, I get an error Error: Could not open send broadcast.

. I must mention that the same code works well on the iPhone the watch is connected to.

Due to these reasons, I am afraid that the above code will not work due to problems with beta versions, from the scope of my code. I would like to know if you think otherwise.

If it's a beta issue, I can't wait to get it fixed, so I wanted to ask any idea here on how to send data that matches the following points:

  • Basically a way to send traffic directly from a chat to a UDP server on the local network.
  • The data must be sent at the time it is received (so combining multiple data points is not an option)
  • UDP is preferred, but any other way of sending low latency streams is fine.
  • This is a hackathon project that is a proof of concept for a really cool idea. Meaning, AppStore compliance or battery issues do not apply here.

Any help would be greatly appreciated!

Thank you very much :) Dan


source to share

1 answer

Well, with WatchOS 2 Beta 5, there is still no way to send quick information from the watch.

I found a workaround (with limitations that make it unusable for production) - although not the methods mentioned in the comments on the original post could transfer information at a high speed, I noticed that the logs (posted via NSLog()

) hit the Xcode console window very quickly ... I am assuming that Apple is using a low-level Bluetooth communication system to transmit these messages.

I wrote a short script to read these logs from Xcode, thus getting the data from the clock in real time. With a mac, I could send it wherever I want (and even process it along the way if I want). The solution and its limitations are described here - Reading syslog in Apple Watch (NSLog ()) in real time .



All Articles