Skip to content

Instantly share code, notes, and snippets.

@rossmartin
Created December 31, 2012 00:33
Show Gist options
  • Save rossmartin/4416377 to your computer and use it in GitHub Desktop.
Save rossmartin/4416377 to your computer and use it in GitHub Desktop.
GCDAsyncSocket delegate. This shows how to queue a read in AsyncSocket.
// GCDAsyncSocket delegate, this occurs when the server has sent the message asking the client to send JSON
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
{
if (tag == TAG_ASK_FOR_JSON) {
NSLog(@"didWriteDataWithTag tag (TAG_ASK_FOR_JSON) in SocketServerDelegate.m - First Request sent from server to device sending JSON, asking it to send JSON data");
// Now start the queue to read in the JSON stream from the client
[sock readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:TAG_READ_JSON_DATA]; // parse all the way to CRLF
// You can even specify what should be used as a terminator for a byte stream
//NSData *term = [@"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding];
//[socket readDataToData:term withTimeout:-1 tag:HTTP_HEADER];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment