Skip to content

Instantly share code, notes, and snippets.

@icanswiftabit
Created December 6, 2013 09:43
Show Gist options
  • Save icanswiftabit/7821120 to your computer and use it in GitHub Desktop.
Save icanswiftabit/7821120 to your computer and use it in GitHub Desktop.
//sender
NSData *data2 = [self createRandomNSData:8192];
NSMutableData *dataToSend =[NSMutableData data];
[dataToSend appendBytes:&tag length:sizeof(int)];
float currentTimeStamp = CACurrentMediaTime();
[dataToSend appendBytes:&currentTimeStamp length:sizeof(float)];
[dataToSend appendData:data2];
NSLog(@"%i || %f || %lu",tag, currentTimeStamp,(unsigned long)[dataToSend length]);
[_udpSocket sendData:dataToSend toHost:@"230.0.0.1" port:_port withTimeout:-1 tag:tag];
tag++;
//reciver
char* dataBytes = [data bytes];
int inTag;
float inCurrentTimeStamp;
[data getBytes:&inTag length:sizeof(int)];
[data getBytes:&inCurrentTimeStamp range:NSMakeRange(sizeof(int), sizeof(float))];
float currentTimeStamp = CACurrentMediaTime();
float timeStampDiff = currentTimeStamp - inCurrentTimeStamp;
NSLog(@"%i || %f || %lu",inTag, timeStampDiff,(unsigned long)[data length]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment