Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. - (void) sendit:(char[500])dref value:(float)v {
  2.  
  3. int sock = 0; /// ?
  4.  
  5. NSLog(@"starting udp testing");
  6.  
  7. if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
  8. NSLog(@"Failed to create socket, error=%s", strerror(errno));
  9. }
  10.  
  11. struct sockaddr_in destination;
  12. //memset(&destination, 0, sizeof(struct sockaddr_in));
  13. memset(&destination, 0, sizeof(destination));
  14.  
  15. //destination.sin_len = sizeof(struct sockaddr_in);
  16. destination.sin_family = AF_INET;
  17.  
  18. NSString *ip = @"192.168.1.109";
  19. destination.sin_addr.s_addr = inet_addr([ip UTF8String]);
  20. destination.sin_port = htons(49000); //port
  21.  
  22.  
  23. /* server port */
  24. setsockopt(sock,
  25. IPPROTO_IP,
  26. IP_MULTICAST_IF,
  27. &destination,
  28. sizeof(destination));
  29.  
  30.  
  31. ////////
  32. char data_send[509];
  33. memset(&data_send, 0, sizeof(data_send));
  34. struct dref_struct mystruct;
  35. mystruct.var = v;
  36. strcpy(mystruct.dref_path, dref);
  37.  
  38. data_send[0] = 'D';
  39. data_send[1] = 'R';
  40. data_send[2] = 'E';
  41. data_send[3] = 'F';
  42. data_send[4] = 0;
  43.  
  44. memcpy(&data_send[5], &mystruct, sizeof(struct dref_struct));
  45. NSLog(@"Size: %lu", sizeof(struct dref_struct));
  46.  
  47. if (sendto(sock, data_send , sizeof(struct dref_struct)+5, 0, (struct sockaddr *) &destination, sizeof(destination)) == -1) {
  48. NSLog(@"did not send");
  49. } else {
  50. NSLog(@"did send");
  51. }
  52.  
  53. close(sock);
  54. //shutdown(sock, 1);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement