stream

How can I create a stream where the items are based on items that the stream previously returned?

☆樱花仙子☆ 提交于 2020-01-24 11:48:05
问题 I have a function that generates a futures::Stream based on an argument. I want to call this function multiple times and flatten the streams together. Complicating matters is the fact that I want to feed the values returned by the stream back as the argument to the original function. Concretely, I have a function that returns a stream of numbers down to zero: fn numbers_down_to_zero(v: i32) -> impl Stream<Item = i32> { stream::iter((0..v).rev()) } I want to call this function starting at 5.

Controlled/manual error/recovery handling in stream-based applications

风格不统一 提交于 2020-01-24 11:21:35
问题 I am working on an application based on Apache Flink , which makes use of Apache Kafka for input and out. Possibly this application will be ported to Apache Spark , so I have added this as a tag as well, and the question remains the same. I have the requirement that all incoming messages received via kafka must be processed in-order, as well safely be stored in a persistence layer (database), and no message must get lost. The streaming-part in this application is rather trivial/small, as the

Controlled/manual error/recovery handling in stream-based applications

青春壹個敷衍的年華 提交于 2020-01-24 11:18:07
问题 I am working on an application based on Apache Flink , which makes use of Apache Kafka for input and out. Possibly this application will be ported to Apache Spark , so I have added this as a tag as well, and the question remains the same. I have the requirement that all incoming messages received via kafka must be processed in-order, as well safely be stored in a persistence layer (database), and no message must get lost. The streaming-part in this application is rather trivial/small, as the

Ensure streamreader doesn't hang waiting for data

人走茶凉 提交于 2020-01-23 09:17:12
问题 The code below reads everything there is to read from tcp client stream, and on the next iteration it will just sit there on the Read() (i'm assuming waiting for data). How can I ensure it doesn't and just returns when there's nothing there to read? Do I have to set low timeout, and respond to an exception when it fails out? Or there's a better way? TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect(ip, port); Stream stm = tcpclnt.GetStream(); stm.Write(cmdBuffer, 0, cmdBuffer.Length); byte

Difference between Stream.CopyTo and MemoryStream.WriteTo

爷,独闯天下 提交于 2020-01-23 04:15:11
问题 I have a HttpHandler returning an image through Response.OutputStream . I have the following code: _imageProvider.GetImage().CopyTo(context.Response.OutputStream); GetImage() method returns a Stream which is actually a MemoryStream instance and it is returning 0 bytes to the browser. If i change GetImage() method signature to return a MemoryStream and use the following line of code: _imageProvider.GetImage().WriteTo(context.Response.OutputStream); It works and the browser gets an image. So

Sending Image Stream over Socket Issue - Android

送分小仙女□ 提交于 2020-01-22 15:59:05
问题 I've implemented an application that takes a picture with the SP camera and sends it over a socket to the server. I'm using the following code to read the image file stored locally and send it in successive chunks over the socket: FileInputStream fileInputStream = new FileInputStream( "my_image_file_path" ); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[16384]; try { while( (nRead = fileInputStream.read(data, 0, data.length)) != -1 ){ buffer

Convert a uint16_t to char[2] to be sent over socket (unix)

廉价感情. 提交于 2020-01-22 09:30:50
问题 I know that there are things out there roughly on this.. But my brains hurting and I can't find anything to make this work... I am trying to send an 16 bit unsigned integer over a unix socket.. To do so I need to convert a uint16_t into two chars, then I need to read them in on the other end of the connection and convert it back into either an unsigned int or an uint16_t, at that point it doesn't matter if it uses 2bytes or 4bytes (I'm running 64bit, that's why I can't use unsigned int :) I'm

Convert a uint16_t to char[2] to be sent over socket (unix)

天涯浪子 提交于 2020-01-22 09:30:08
问题 I know that there are things out there roughly on this.. But my brains hurting and I can't find anything to make this work... I am trying to send an 16 bit unsigned integer over a unix socket.. To do so I need to convert a uint16_t into two chars, then I need to read them in on the other end of the connection and convert it back into either an unsigned int or an uint16_t, at that point it doesn't matter if it uses 2bytes or 4bytes (I'm running 64bit, that's why I can't use unsigned int :) I'm

Why do most serializers use a stream instead of a byte array?

隐身守侯 提交于 2020-01-22 08:20:25
问题 I am currently working on a socket server and I was wondering Why do serializers like XmlSerializer BinaryFormatter Protobuf-net DataContractSerializer all require a Stream instead of a byte array? 回答1: It means you can stream to arbitrary destinations rather than just to memory. If you want to write something to a file, why would you want to create a complete copy in memory first? In some cases that could cause you to use a lot of extra memory, possibly causing a failure. If you want to

Passing a Text Stream from NodeJS to Browser

萝らか妹 提交于 2020-01-21 19:13:24
问题 I am trying to stream a text file processed in NodeJS to a browser. The following is the text file before processing. The file is named dbUsers.json. {"userId":443,"email":"bob@gmail.com","hashedPassword":"36583a77a098c02ef111e2f2521d77b58e420f2bc7e9bf930ec24b21d42ea2e0","timeStamp":1567439821109,"deleted":false} {"userId":447,"email":"alice@gmail.com","hashedPassword":"36583a77a098c02ef111e2f2521d77b58e420f2bc7e9bf930ec24b21d42ea2e0","timeStamp":1567439909013,"deleted":false} {"userId":451,