NSOutputStream 刷新
我正在开发一个 iPhone 应用程序,想要使用:
CFStreamCreatePairWithSocketToHost(NULL, url, port, &serverReadStream, &serverWriteStream);
然后使用:
[serverWriteStream write:[sendData bytes] maxLength:[sendData length]];
我想发送 5 字节的小包来获取实时更新。
我现在的问题是,流仅在缓冲区已满时发送数据。所以我需要某种刷新方法或告诉流立即发送数据。
搜索这个问题最终发现“TCP_NODELAY”,它似乎属于未记录的API(我不能将其用于AppStore,如果我错了请纠正我),即使我可能被允许使用它,我也必须改变流的创建,对吗?
I'm working on an iPhone App and wanted to use:
CFStreamCreatePairWithSocketToHost(NULL, url, port, &serverReadStream, &serverWriteStream);
And after that use the:
[serverWriteStream write:[sendData bytes] maxLength:[sendData length]];
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cocoa NSOutputStream 发送到连接
只需添加一个“行尾”(“ \n" ) 到你的字符串。为我工作。
Cocoa NSOutputStream send to a connection
Just add an "end of line" ( "\n" ) to your string. work for me.