Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent result for [NSDate date] in several devices
    text
    copied!<p>To start, I have to say that I set autoset in date&amp;time settings and time zone is the same for each device. So I use <code>[NSDate date]</code> to get time stamp in milliseconds, then encode to <code>NSData</code> and send to another device. On receiver data is being decoded and subtract with new <code>[NSDate date]</code>. So that I get total time needed for send and receive message. That I was thought because when sender is iPhone 4 iOS6 and receiver is iPhone 5 iOS7 then receiver have earlier time stamp than sender. I don't know why? Maybe <code>[NSData date]</code> isn't the most reliable class for that kind of operations? I use <code>GCDAsyncUdpSocket</code> for sending/receiving UDP.</p> <p>Code sender</p> <pre><code>NSData *data2 = [self createRandomNSData:8192]; NSMutableData *dataToSend =[NSMutableData data]; [dataToSend appendBytes:&amp;tag length:sizeof(int)]; long long currentTimeStamp = (long long)([[NSDate date] timeIntervalSince1970]*1000.0); [dataToSend appendBytes:&amp;currentTimeStamp length:sizeof(long long)]; [dataToSend appendData:data2]; NSLog(@"%i || %lld || %lu",tag, currentTimeStamp,(unsigned long)[dataToSend length]); [_udpSocket sendData:dataToSend toHost:@"230.0.0.1" port:_port withTimeout:-1 tag:tag]; tag++; </code></pre> <p>Code receiver</p> <pre><code>char* dataBytes = [data bytes]; int inTag; long long inCurrentTimeStamp; [data getBytes:&amp;inTag length:sizeof(int)]; [data getBytes:&amp;inCurrentTimeStamp range:NSMakeRange(sizeof(int), sizeof(long long))]; long long currentTimeStamp = (long long)([[NSDate date] timeIntervalSince1970]*1000.0); long long timeStampDiff = currentTimeStamp - inCurrentTimeStamp; self.delay = timeStampDiff; NSLog(@"%i || %lld || %lu",inTag, timeStampDiff,(unsigned long)[data length]); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload