Я пытаюсь отправить данные между двумя устройствами iOS, используя пример кода из http://code.google.com/p/iphonebits/source/browse/trunk/src/TicTacToeNew/
Клиент хорошо подключается, и данные передаются между двумя устройствами просто отлично.Клиент отправляет пакеты данных примерно 10 раз в секунду.Тем не менее, я получаю очень странные паузы между полученными данными.
В коде получения я помещаю отладочную инструкцию каждый раз, когда поступает запрос:
- (void) stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
NSLog(@"stream: handleEvent : %d", eventCode);
switch(eventCode) {
// ... handle event and print out received data
}
}
СоответствующийКод отправки находится в функции sendQueuedData здесь: http://code.google.com/p/iphonebits/source/browse/trunk/src/TicTacToeNew/Classes/OnlineSession.m?r=19
Первая секунда или около того запросов идет, как и планировалось (хотя кажется, что пакетные запросы вместе):
2011-03-13 12:28:08.759 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":1.98,"y":0.01}
[DEBUG] Fire Event: data: {"x":1.98,"y":0.00}
[DEBUG] Fire Event: data: {"x":2.11,"y":0.01}
2011-03-13 12:28:08.781 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":2.07,"y":0.03}
[DEBUG] Fire Event: data: {"x":2.02,"y":0.03}
2011-03-13 12:28:08.923 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":1.98,"y":0.01}
[DEBUG] Fire Event: data: {"x":1.86,"y":0.01}
2011-03-13 12:28:08.996 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":1.73,"y":0.01}
2011-03-13 12:28:09.171 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":2.38,"y":-0.56}
2011-03-13 12:28:09.182 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:09.332 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:09.496 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:09.501 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:09.598 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
...но затем обратите внимание на отметки времени при последующих вызовах:
2011-03-13 12:28:10.163 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:13.770 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:13.772 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:13.777 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:13.868 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:14.016 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:14.177 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:14.340 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:14.424 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:15.065 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:16.338 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:18.740 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
2011-03-13 12:28:18.741 bluetoothmodule[52188:207] stream: handleEvent : 2
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
[DEBUG] Fire Event: data: {"x":0.00,"y":-0.00}
Как видите, обратный вызов handleEvent () вызывается спорадически и, очевидно, не подходит для приложения реального времени.Кто-нибудь знает почему?Должен ли я переключаться с использования NSStreams на что-то вроде http://code.google.com/p/cocoaasyncsocket/ с UDP?