title: Send a stream of data from WatchKit
body: <p>For a project I'm doing on the Apple Watch, I'm looking for a way to send streams of data to a server on the local network. This is rapid, online data, so I preferred it would be sent over UDP (but it wasn't a strict requirement for me). The data is the current accelerometer reading from the watch, which is read every fraction of a second.</p>
  
  <p>I'm using WatchOS 2 (Beta 4), iOS 9 (Beta 4) (and the latest beta of Xcode 7).</p>
  
  <p>I've used the following code:</p>
  
  <pre><code>- (void) sendMsg: (NSString *)msg{
      int socketSD = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if (socketSD &lt;= 0) {
          NSLog(@"Error: Could not open socket.");
          return;
      }
  
      // set socket options enable broadcast
      int broadcastEnable = 1;
      int ret = setsockopt(socketSD, SOL_SOCKET, SO_BROADCAST, &amp;broadcastEnable, sizeof(broadcastEnable));
      if (ret) {
          NSLog(@"Error: Could not open set socket to broadcast mode");
          close(socketSD);
          return;
      }
  
      // Configure the port and ip we want to send to
      struct sockaddr_in broadcastAddr;
      memset(&amp;broadcastAddr, 0, sizeof(broadcastAddr));
      broadcastAddr.sin_family = AF_INET;
      inet_pton(AF_INET, SERVER_IP, &amp;broadcastAddr.sin_addr);
      broadcastAddr.sin_port = htons(SERVER_PORT);
  
      char *request = "Message from Watch";
      ret = sendto(socketSD, request, strlen(request), 0, (struct sockaddr*)&amp;broadcastAddr, sizeof(broadcastAddr));
      if (ret &lt; 0) {
          NSLog(@"Error: Could not open send broadcast.");
          close(socketSD);
          return;
      }
  }
  - (IBAction)watchGoButtonTouched {
      [self sendMsg:@"Hi"];
  }
  </code></pre>
  
  <p>Which succeeds in getting the message to the server <em>in the Watch simulator</em>, but when ran on the actual watch, I get the error <code>Error: Could not open send broadcast.</code>.
  I should mention that the same code works well on the iPhone that the watch is connected to.</p>
  
  <p>Due to these reasons, I'm afraid the above code fails because of beta issues, out of the realm of my code. I would love to know if you think otherwise.</p>
  
  <p>If it is a beta issue, I cannot wait for it to be fixed, so I wanted to ask here for any idea as to how to send data that conforms to the following points:</p>
  
  <ul>
  <li>Basically, a way to send traffic directly from the watch to a UDP server on the local network.</li>
  <li>The data has to be sent at the moment it is received (so concatenating multiple data points is not an option)</li>
  <li>UDP is preferable, but any other way of sending streams of data with low latency is good.</li>
  <li>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.</li>
  </ul>
  
  <p>Any help will be much appreciated!</p>
  
  <p>Thanks a lot :)
  Dan</p>