Note that there are some explanatory texts on larger screens.

plurals
  1. POGCDAsyncSocket read data issue
    primarykey
    data
    text
    <p>I have a Cocoa live video program that uses GCDAsyncSocket as the network interface library. There is obvious sluggish when playing the video frames. For example, the time on the video goes almost twice as slow as normal. By inspecting the performance, I found that the GCDAsyncSocket's readDataToLength method is called too sparsely. Below is the log with time stamp:</p> <pre><code>2012-05-16 11:18:27.054 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.256 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.285 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.452 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.475 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.697 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.726 DVRLibDemo[1181:903] readDataToLength 2012-05-16 11:18:27.856 DVRLibDemo[1181:903] readDataToLength </code></pre> <p>I set a separate delegate dispatch queue when creating the socket, but it does not help much. The message has a fixed header and I read the header firstly then the payload.</p> <pre><code>- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { DVRConnection *conn = [self getConnectionWithSocket:sock]; //DebugLogInfo(@"Receive raw data: %@ for connection: %d", data, conn.tag); if (conn != nil &amp;&amp; conn.connected) { if (tag == TAG_XM_MESSAGE_HEADER) { uint32_t bodyLen = [_parser parseMessageHeader:data]; [sock readDataToLength:bodyLen withTimeout:-1 tag:TAG_XM_MESSAGE_PAYLOAD]; } else if (tag == TAG_XM_MESSAGE_PAYLOAD) { [_parser parseMessage:data forConnection:conn device:self]; [sock readDataToLength:XM_MESSAGE_HEADER_LENGTH withTimeout:-1 tag:TAG_XM_MESSAGE_HEADER]; } } } </code></pre> <p>Does anyone have any idea to improve the speed of reading data from socket? thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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