Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top