CRLF at the end of data

92 views
Skip to first unread message

Simeon Mitev

unread,
May 1, 2012, 11:32:52 AM5/1/12
to CocoaAsyncSocket
Do I always need to append CRLF at the end of data in order to avoid any
network packet shipment delay?

[data appendData:[GCDAsyncSocket CRLFData]];

Thanks

Robbie Hanson

unread,
May 1, 2012, 12:05:13 PM5/1/12
to cocoaasy...@googlegroups.com
It doesn't really have anything to do with delay. This should help clear things up for you:

https://github.com/robbiehanson/CocoaAsyncSocket/wiki/CommonPitfalls

-Robbie Hanson
Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "CocoaAsyncSocket" group.
> To post to this group, send email to cocoaasy...@googlegroups.com.
> To unsubscribe from this group, send email to cocoaasyncsock...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cocoaasyncsocket?hl=en.
>

Simeon Mitev

unread,
May 1, 2012, 12:53:15 PM5/1/12
to cocoaasy...@googlegroups.com
Agreed. TCP has nothing to do with the data get actually sent.

I have another question related to the options being set to the socket
during socket initialization.

I did not find any other way to set TCP_NODELAY to 1. I had to put these
lines into the source code:

int flag = 1;
int result = setsockopt(socketFD, IPPROTO_TCP, TCP_NODELAY, (char
*)&flag, sizeof(int));
if (result == -1) {
NSString *reason = @"Could Not Disable Nagle...";
err = [[self errnoErrorWithReason:reason] retain];
close(socketFD);
return SOCKET_NULL;
}

Personally I prefer to have a getter which provides me with the socket
structure or some call back function getting invoked during socket
initialization.

Have I missed something?

Robbie Hanson

unread,
May 1, 2012, 9:14:13 PM5/1/12
to cocoaasy...@googlegroups.com
You can do this without modifying GCDAsyncSocket. Check out the header file for getter methods for the socketFD.

You could, for example, set the nodelay flag in socketDidConnect.

PS - there is a caveat to this which you may find odd. You'll need to execute your code within a performBlock (another method documented in the header). But when you read the documentation for it, you'll see why.

- (void)socket:(...)sender didConnect:(...)addr {
[asyncSocket performBlock:^{
int socketFD = [asyncSocket socketFD];
... your nagle stuff here...
}];
}

-Robbie Hanson
Sent from my iPhone

Simeon Mitev

unread,
May 2, 2012, 4:09:03 AM5/2/12
to cocoaasy...@googlegroups.com
It worked! Thank you Robbie.
Reply all
Reply to author
Forward
0 new messages