Having trouble programming streams

青春壹個敷衍的年華 提交于 2019-11-29 12:53:19

You are reading with this:      

[asyncSocket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:2];

Which expects a CRLF as a separator of the stream. But I don't see where you append it to your JSONRequestData. So modifying your JSONRequestData to be mutable, like so:

NSMutableData *JSONRequestData;

And then before this line:

 

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

Add this:

[JSONRequestData appendData:[GCDAsyncSocket CRLFData]];

When sending short chunks of data always flush the buffer after each write which you want to have an immediate effect.
I don't see you doing that in your code.
If you don't do it then the buffer will be flushed only when it is full or the stream is closed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!