Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) sendit:(char[500])dref value:(float)v {
- int sock = 0; /// ?
- NSLog(@"starting udp testing");
- if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
- NSLog(@"Failed to create socket, error=%s", strerror(errno));
- }
- struct sockaddr_in destination;
- //memset(&destination, 0, sizeof(struct sockaddr_in));
- memset(&destination, 0, sizeof(destination));
- //destination.sin_len = sizeof(struct sockaddr_in);
- destination.sin_family = AF_INET;
- NSString *ip = @"192.168.1.109";
- destination.sin_addr.s_addr = inet_addr([ip UTF8String]);
- destination.sin_port = htons(49000); //port
- /* server port */
- setsockopt(sock,
- IPPROTO_IP,
- IP_MULTICAST_IF,
- &destination,
- sizeof(destination));
- ////////
- char data_send[509];
- memset(&data_send, 0, sizeof(data_send));
- struct dref_struct mystruct;
- mystruct.var = v;
- strcpy(mystruct.dref_path, dref);
- data_send[0] = 'D';
- data_send[1] = 'R';
- data_send[2] = 'E';
- data_send[3] = 'F';
- data_send[4] = 0;
- memcpy(&data_send[5], &mystruct, sizeof(struct dref_struct));
- NSLog(@"Size: %lu", sizeof(struct dref_struct));
- if (sendto(sock, data_send , sizeof(struct dref_struct)+5, 0, (struct sockaddr *) &destination, sizeof(destination)) == -1) {
- NSLog(@"did not send");
- } else {
- NSLog(@"did send");
- }
- close(sock);
- //shutdown(sock, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement