问题标签 [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.

0 投票
1 回答
1294 浏览

ftp - 将 .txt 文件读入 NSInputstream 返回文件流没有可用字节

我使用 NSInputstream 从文件中读取。阅读后,NSInputstream内容为空。我使用了代码(用于将.txt文件传输到ftp服务器)

{ AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

}

它打印,“文件存在”但在下一行“没有内容”

该文件不为空。

0 投票
1 回答
1294 浏览

objective-c - 在使用 AVCaptureMovieFileOutput 写入时使用 NSInputStream 读取 .mov 文件

目标:用于AVCaptureMovieFileOutput将视频录制到 .mov 文件。在录制视频时,我想将其上传到 S3。上传部分应该是可行的多部分上传。(Mac OS X +10.8 应用程序)

问题:我如何从块中读取 .mov 文件,而文件正在被写入AVCaptureMovieFileOutput并不断增大?

到目前为止我做了什么:

此时我开始stream:handleEvent:在委托对象上接收消息NSStreamEventHasBytesAvailable。但是几秒钟后,消息停止进入(在 250.000-300.000 字节 (0.2MB) 的总字节数之后)即使 .mov 文件的大小增长到 >10MB,也会发生这种情况。

问题:

  1. 为什么NSInputStream委托不继续接收流事件?

  2. 最初可用的数据是否不可靠?

  3. 这总体上是一种可行的方法吗?还是有另一种方法可以实现我想要的?

谢谢!

0 投票
0 回答
251 浏览

ios - 解析:如何有效地使用 PFFile getDataStreamInBackgroundWithBlock

我正在使用 Parse 的getDataStreamInBackgroundWithBlock方法下载一个大文件并保存在本地。

如何处理流以将数据存储在文件中?这是否可能不使用NSInputStream委托方法(hasBytesAvailable等)?

0 投票
1 回答
1461 浏览

sockets - NSInputStream can't read from TCP Connection [TCP-Server]

I created a TCP server using this (quite old) example by Apple. My server is up and running, listening on the specified Port for incoming connections.

Everything looks perfect, my client app can connect to the server and -stream:handleEvent: is called as expected.

But when I now write to the stream, the server kind of rejects my connection. The client says that 30 Bytes has been written successfully.

But my logs say:

In the client side I'm using following code to establish the connection:

On the server side this creates the socket (a CFSocketCallBack is provided)

Then in the callback I'm pairing using this:

And then bridge cast the streams to NSStreams, set the delegate, schedule in in current runloop and open them.

I'm not quite sure why this can happen so I don't provide the whole server code here. It would be simply too much.

When you need a specific piece of code or guess where it could be caused, I'll post the respective code here.

UPDATE

I now did a lot of research in my own code. I tracked the issue down to my -stream:handleEvent method invocation.

UPDATE 2

I read this great Apple Article about TCP Servers and clients. I walked through all the steps and my program is almost identical with the code provided by Apple. The problem remains.

0 投票
0 回答
3865 浏览

ios - iOS - 带有套接字的 NSInputStream:后台线程

我有一个使用以下代码创建的 SocketCommunication 类

一切正常。但是委托是在 UI 线程中调用的。在某些情况下,解析数据可能需要一些时间。

我如何告诉 NSInputStream 在后台线程中调用委托?

也许有一个自己的 NSRunLoop?

0 投票
1 回答
4309 浏览

ios - iOS7常量与表达式的比较总是假的

在适用于 iOS 5 和 6 的应用程序中,我有一个if声明:

在 iOS 7 上,我收到以下警告:

NSInputstream关于 iOS 7 关于课堂的变化有什么想法吗?我想知道为什么我现在在 iOS7 上收到此警告。

0 投票
0 回答
393 浏览

objective-c - 反序列化 json 流时出错

我有一个NSInputStream *inputStream从网络连接接收小的 JSON 对象。如果我像这样将流读入缓冲区:

然后我得到了我期望的 JSON;但这非常脆弱,因为它假设只有一个 JSON 对象要读取。使用这个方案,我最终可能会尝试反序列化{"cheese":17}{"ch,这显然是无效的。我宁愿用

但是,但是通过调试器,我发现最后一行没有返回,并且没有记录错误!什么是正确的方法?

0 投票
2 回答
1768 浏览

ios - iOS - 将输入流的委托设置为另一个类

我想知道是否可以将输入流的委托设置为另一个类。到目前为止,我遇到的所有示例都是 self: [inputStream setDelegate:self]。我想将委托设置为另一个类,例如ViewController非自我。提前致谢。

0 投票
1 回答
2724 浏览

objective-c - 写入后 NSOutputStream 因访问错误而崩溃(Objective-c)

我一直在尝试为我的 iOS 应用程序启动并运行一个基本的 TCP 客户端,但遇到了一个我似乎无法解决的问题。

到目前为止,我可以连接,发送一条在服务器端收到的消息,但随后我的应用程序崩溃了。

客户端.h

客户端.m

控制台中的输出是

看起来,我的消息已发送,我收到流事件 #4,然后我遇到了错误的访问崩溃。问题是我不知道它在访问时遇到了什么问题?

任何帮助将不胜感激!

0 投票
1 回答
337 浏览

c# - 如何从 Web 服务获取类型流的数据

我想用相应的 URL 从服务器读取流数据,目前我正在尝试使用 NSInputStream 读取数据,但我收到错误“错误 2 操作无法完成。没有这样的文件或目录”。Web 开发人员以字节形式接收数据,然后他将该数据转换为 Stream,如 MemoryStream(byteData)[注意:Web 服务是用 .net 编写的],并返回给我。读取这种数据的方法是什么我尝试了 AISHTTPRequest 得到了大小为 0 字节的文件,我再次尝试了 NSURLConnction 我得到了大小为 0 字节的文件,现在我正在使用 NSInputStream 我得到了提到的错误在开始。这是我的 NSInputStream 代码,

请指导我是否可以读取这种数据是iOS作为前端,如果是,那么指导我应该如何与这种数据进行交互。如果 NSInputStream 是与之交互的预期方式,那么下面编写的代码中的问题是什么。