NSOutputStream冲洗 [英] NSOutputStream flushing
问题描述
我正在使用iPhone应用程序,并且想使用:
I'm working on an iPhone App and wanted to use:
CFStreamCreatePairWithSocketToHost(NULL, url, port, &serverReadStream, &serverWriteStream);
然后使用:
[serverWriteStream write:[sendData bytes] maxLength:[sendData length]];
我想发送5字节的小包以获取实时更新.
I want to send small Packages of 5 Bytes to get realtime updates.
我的问题是,流仅在缓冲区已满时才发送数据.因此,我需要某种冲洗方法或告诉流立即发送数据.
My problem is now, that the stream only sends data when the buffer is full. So I need some kind of a flush method or tell the stream to immediately send the data.
搜索此问题的结果是找到似乎属于未记录API的"TCP_NODELAY"(我不能将其用于AppStore,如果我输入错误,请纠正我),即使我可能被允许使用它,我会不得不改变流的创建,对吧?
Searching for this problem ended in finding 'TCP_NODELAY' which seems to belong to the undocumented API ( which I mustn't use for AppStore, correct me if im wrong pls ) and even if I might be allowed to use it, I would have to change the creation of the streams, right?
推荐答案
只需在字符串中添加一个行尾"("\ n").为我工作.
Just add an "end of line" ( "\n" ) to your string. work for me.
这篇关于NSOutputStream冲洗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!