khaliq
khaliq

Reputation: 3115

GCDAsyncSocket for iOS is not writing out the buffer

Basically I write an NSData object:

[asyncSocket writeData:JSONRequestData withTimeout:-1 tag:1];

Which when run, invokes the delegate

- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag

But for some reason, when the write goes to the buffer... it's not written out to the server.

When I stop my build, I guess the socket decides to write everything and the server ends up seeing it.

How would I fix this? There's no way to flush a CocoaAsyncSocket since it's not necessary... I've tried adding line endings, like "/n" and all, but that doesn't do anything either.

Upvotes: 2

Views: 2362

Answers (1)

khaliq
khaliq

Reputation: 3115

This is based on user523234's suggestion.

Basically the NSData that you're writing out needs to have some kind of signal to tell the socket that no more data will be coming in.

I appended

[GCDAsyncSocket CRLFData];

to the NSData object

Note: to use the

appendData:

Method, you must convert NSData to NSMutableData.

Upvotes: 5

Related Questions