问题标签 [nsinputstream]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ios - 如果 [nsInputStream close] 被另一个线程调用,是否应该返回 [nsInputStream read:...]?
在我看来,如果流被另一个线程关闭,无论套接字连接的另一端如何,任何 NSInputStream 对象都应该从它的 read: 方法中弹出。但在某些情况下,这似乎不是真的。似乎除非对方首先在连接上至少发送一次,否则 read: 方法将不会响应流关闭。
打开连接的代码:
关闭连接的代码:
在接收线程中:
当我从主线程关闭流时,接收线程仍保留在读取方法中。最终它超时并崩溃。即使崩溃也不会导致任何类型的对象被抛出(我试图包围代码以捕获任何东西(id)并且什么也没有得到)。
每次要关闭流时,如何可靠地强制读取弹出?
此外:
我在 ML 上使用 XCODE 4.4.1 和 5.1 iPad 模拟器。
如果我只关闭 inputStream 而没有释放或设置为 nil,那么也会出现问题。
ios - 如何获取流字节并转换回图像 - IOS
如何获取流字节并转换回图像,下面是我的代码。但是我得到的图像是空白的。为什么?代码有问题吗?
我从我的 NSOutputStream 中获取字节并转换回 NSData,然后将 NSData 转换为图像。
}
objective-c - NSInputStream 读取:maxlength:返回的字节数比 maxlength 多
我有一个 iOS 应用程序,我在其中使用 NSInputStream(基于 CFReadStreamRef)从网络套接字读取。我不断从服务器获取数据,并不断读取和处理它(使用read:bytesBuffer maxLength:l)。前几次它运行良好,但在大约第 20-25 次读取时,此方法报告它读取了大量字节,例如,当我真正要求最大1-3MBytes时,它读取了4,294,967,295字节。这很奇怪,似乎是 NSInputStream/CFReadStream API 中的一个错误。
我的应用程序最终崩溃,因为它试图将所有这些字节加载到一个没有为返回的字节数分配的缓冲区中(并且服务器首先没有返回这么多字节!)
有没有人遇到过这个问题?
谢谢!
ios - NSInputStream 的 NSStreamEventHasBytesAvailable 永远不会被调用
我正在创建一个类似于 WiTap 的应用程序(但要连接许多设备),这是我的问题:应用程序似乎连接了设备(它们显示在表视图控制器中。代表NSInput/OutputStream
说两个流都已打开,但是当我发送数据包时比NSOutputStream
对面设备上的函数没有NSInputStream
被调用(NSStreamEventHasBytesAvailible
。- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode)
这是进行连接以及发送和接收的代码......
我尝试使用 Instruments(网络事物)调试项目。它说数据包已发送和接收,但该事件从未发生。谢谢您的帮助。如果有人想要,我可以毫无问题地发送整个项目......
iphone - 从 iDevice 上传视频到 FTP
我正在开发一个 APP 供用户将视频上传到我们的 FTP 服务器
到目前为止,一切都差不多完成了,但我遇到一个问题是用户上传视频(.MOV)后,我无法打开和播放文件。
quicktime播放器返回的错误信息是“无法打开,因为无法识别电影的文件格式”
在我的代码中,我让用户使用 ALAssetsLibrady 选择视频
然后将视频加载到 ALAsset 对象中,在开始上传之前,将视频从 ALAsset 加载到 NSInputStream 对象中,这里是代码。
下一步是设置一个 NSOutputStream 并打开它,通过以下代码处理上传操作。
没有任何错误发生,视频文件确实以正确的文件大小和名称上传到 FTP,但无法打开它。
有人知道任何线索吗?
iphone - 您如何逐行阅读 Objective-C 中呈现的网站的 html 代码?
因此,我在阅读 Java 网站的渲染 html 源代码方面拥有丰富的经验。然而,我已经彻底研究了如何在 Objective-C 中做同样的事情,并且已经能够提出一个应该有效的解决方案,但它没有。这个想法是我想阅读每一行,例如:“view-source:www.apple.com”,我想逐行阅读该页面的结果。我不想要任何 Html 解析器等。这就是我所拥有的:
这可以正常运行和编译,但结果始终为 0。我再次进行了大量研究,但我不明白为什么结果为 0。感谢任何帮助。
ios - Streaming NSXMLParser with NSInputStream
Update:
When using NSXMLParser
class method initWithContentsOfURL
, rather than parsing as the XML feed is downloaded, it appears to try to load the entire XML file into memory, and only then initiate the parsing process. This is problematic if the XML feed is large (using an excessive amount of RAM, inherently inefficient because rather than parsing in parallel with the download, it only starts the parsing once the download is done, etc.).
Has anyone discovered how to parse as the feed is being streamed to the device using NSXMLParser
? Yes, you can use LibXML2
(as discussed below), but it seems like it should be possible to do it with NSXMLParser
. But it's eluding me.
Original question:
I was wrestling with using NSXMLParser
to read XML from a web stream. If you use initWithContentsOfURL
, while the interface may lead one to infer that it would stream the XML from the web, it doesn't seem to to do so, but rather appears to attempt to load the entire XML file first before any parsing taking place. For modest sized XML files that's fine, but for really large ones, that's problematic.
I have seen discussions of using NSXMLParser
in conjunction with initWithStream
with some customized NSInputStream
that is streaming from the web. For example, there have been answers to this that suggest using something like the CFStreamCreateBoundPair
referred to in the following Cocoa Builder post and the discussion of Setting Up Socket Streams in the Apple Stream Programming Guide, but I have not gotten it to work. I even tried writing my own subclassed NSInputStream
that used a NSURLConnection
(which is, itself, pretty good at streaming) but I wasn't able to get it to work in conjunction with NSXMLParser
.
In the end, I decided to use LibXML2
rather than NSXMLParser
, as demonstrated in the Apple XMLPerformance sample, but I was wondering if anyone had any luck getting streaming from a web source working with NSXMLParser
. I've seen plenty of "theoretically you could do x" sort of answers, suggesting everything from CFStreamCreateBoundPair
to grabbing the HTTPBodyStream
from NSURLRequest
, but I've yet to come across a working demonstration of streaming with NSXMLParser
.
The Ray Wenderlich article How To Choose The Best XML Parser for Your iPhone Project seems to confirm that NSXMLParser
is not well suited for large XML files, but with all of the posts about possible NSXMLParser
-based work-arounds for streaming really large XML files, I'm surprised I have yet to find a working demonstration of this. Does anyone know of a functioning NSXMLParser
implementation that streams from the web? Clearly, I can just stick with LibXML2
or some other equivalent XML parser, but the notion of streaming with NSXMLParser
seems tantilizingly close.
ios - 需要帮助从 ios 设备上传多个大图像
我使用 alasset 库成功获取了我的 iphone 图片库中的所有图片 url 并存储在一个数组中。现在我正在尝试上传到服务器,这是我的代码:
我尝试了两种方法,但都在迭代大约 10 张图像后崩溃,没有任何崩溃日志。图片不上传到服务器,上传前崩溃。
1:
2:使用 Afnetworking
java - 如何在将 NSInputStream 写入 iOS 中的 NSOutputStream 时读取它?
我正在将一个 Android 应用程序移植到 iPhone(更像是基于 Android 版本改进 iPhone 应用程序),我需要拆分和组合大型未压缩音频文件。
目前,我将所有文件加载到内存中并将它们拆分并组合成单独的函数。它会因 100MB 以上的文件而崩溃。
这是执行此操作所需的新过程:
我有两个录音(file1 和 file2)和一个拆分位置,我希望将 file2 插入到 file1 中。
- 为 file1 和 file2 创建输入流,为 outputfile 创建输出流。
-重写新的 CAF 标头
- 从 inputStream1 读取数据,直到它到达分割点,然后我将所有数据写入输出文件。并将其写入输出流。
- 从 inputStream2 读取所有数据并将其写入输出文件。
- 从 inputStream1 读取剩余数据并将其写入输出文件。
这是我的Android代码:
这是我的 writeBytesToLimit 函数:
我如何在 iOS 中做到这一点?对两个 NSInputStreams 和一个 NSOutputStream 使用相同的委托看起来会变得非常混乱。有没有人看过一个如何做到这一点的例子(并且做得干净)?
ios - IOS NSInputStream
使用 NSInputStream 时遇到问题。我有连接到服务器的客户端应用程序,然后服务器将开始通过 TCP 重复向我的客户端应用程序发送消息,大约每秒 1 条消息。服务器只是向客户端广播消息,消息是 xml 格式。服务器将消息作为一个数据包发送。
现在的问题是,当我从 NSInputStream 读取字节时,数据被截断,这意味着我不时收到 2 个单独的数据(部分 xml)响应,而不是接收 1 个完整的消息。我无法调试,因为当我从 NSInputStream 读取数据字节时它已经发生了。
我使用 Wireshark 分析我收到的每个数据包,当它发生时数据也被截断,因为 TCP 将部分数据重新传输到我的客户端。我试图记录每个部分数据字节,部分数据的总和始终在 1600 字节左右。
我不知道他们是如何设计和实现服务器端的,但我知道有很多人连接到该服务器并不断从中获取广播消息。
有人遇到这个问题吗?任何人都可以帮忙吗?数据是否可能超过最大大小并被拆分?