How to read complete data from the device using Netty? - java

Am developing one java application using netty .In this application it will read data from the device and put it into database .But here the problem is once the device send half data it will read and again the device is sending half data . In threads Thread.sleep() method is there to wait for complete data . In Netty am using Non Blocking Ios(NIO). Please tell me how to wait NIOs to read complete data.
Thanks

You will need to implement your own FrameDecoder which makes sure that the ChannelBuffer will only get based to your business handler once it is complete.
See [1].
[1] https://netty.io/3.9/api/org/jboss/netty/handler/codec/frame/FrameDecoder.html

You can simply use ReplayingDecoder, which will read until data is complete.
Here you can take a look for example.

Related

Stream binary data (created using FlatBuffers) from Node backend and receive in Android frontend

Technology Used:
In the question below, "frontend refers to Android" and "backend to Node.js".
Constraints:
We have rural users in developing market, so the internet may be slow and/or
jittery/unstable. Due to jitter, we need a solution where we can use whatever (if not all) data is transmitted.
We have quite large data (huge list of objects) which we cannot simple transmit through
JSON (via plain REST APIs), as until the whole data is downloaded,
we get nothing (because we are using Retrofit and its onResponse is
not called).
Goal:
To convert the list of objects (in backend) to binary data. So that
when we receive data in the frontend, we are able to access
serialized data without unpacking. Achieving it through FlatBuffers.
To transmit this data through streaming when triggered from
the frontend. I want to stream the data as I want to use (show in UI in
realtime) whatever data (list of objects) user has received (Even if
user gets disconnected during transmission). I am having issues
here, as I am unable to achieve this through REST API - Retrofit
combination. Need help here about what to use for trigger based
streaming.
To reconvert the list of objects in the frontend to Java objects and
show in user's UI. I am using FlatBuffer here, as it is fast and
able to use/serialize whatever objects are transmitted. No need for
entire data transmission to complete.
I am able to successfully implement step 1 & 3 of the goal. But, I am not able to sort out step 2.
Please suggest what is a good and easy way to achieve this (stream binary data from backend to frontend). It would be better, if we can trigger and stream using Retrofit (if possible) in the frontend.
Achieved by difference method:
On the Node side, use fs.createReadStream function for streaming.
On the Android side, use URLConnection, BufferedReader, InputStreamReader for consuming stream.
P.S - Didn't get any way to do it via Retrofit.

Arduino-Processing Serial.send/Serial.get interaction

I'm trying to get my Arduino environment to send data to processing for a data visualization project.
I have managed to get the handshake working and can Serial.println(...) to print the data I need from Arduino to the Processing console. What I need now is to somehow use that data to alter a variable within Processing.
I know that neither of the methods that I mention in the title exist within the Serial class but I was hoping someone would know how to manage this functionality.
Thanks in advance!
I will assume that you are using the serialEvent method in processing. Example code:
String val = myPort.readStringUntil('\n');
Where myPort is the port that your android device is on.

Why couldn't I read a full incoming data by using non-blocking I/O socketchannel

I am trying to testing FTP by using SocketChannel, but it is not really in my expectation. I knew that I need to setup a selector algorithm which select the OP_CONNECT, OP_READ key to perform the connect and read function, everything is working fine but why the incoming data is not completely read? On the other hand, if I'm debugging the program, it can be read correctly as I doing it very slow. I thought it is synchronizing issue, so I try to submit only 1 key(even tried hard coded the method step by step, but the issue still existed.
Has anyone met this issue? How can I ensure that the full incoming data is ready to read instead of partial data only, sometimes no data (=.=")

How do i start reading byte through input stream from a specific Location in the stream?

I am using URL class in java and I want to read bytes through Input Stream from a specific byte location in the stream instead of using skip() function which takes a lot of time to get to that specific location.
I suppose it is not possible and here is why: when you send GET request, remote server does not know that you are interested in bytes from 100 till 200 - he sends you full document/file. So you need to read them, but don't need to handle them - that is why skip is slow.
But: I am sure that you can tell server (some of them support it, some - don't) that you want 100+ bytes of file.
Also: see this to get in-depth knowledge about skip mechanics: How does the skip() method in InputStream work?
The nature of streams mean you will need to read through all the data to get to the specific place you want to start from. You will not get faster than skip() unfortunately.
The simple answer is that you can't.
If you perform a GET that requests the entire file, you will have to use skip() to get to the part that you want. (And in fact, the slowness is most likely because the server has to send all of the data that is being skipped to the client. That is how TCP/IP works ...)
However, there is a possible alternative. The HTTP 1.1 specification supports partial fetching documents using the Range header. If your server supports this, then you can request the server to send you just the range of the document that you are interested in. However, you may need to deal with the case where the server ignores the Range header and sends the entire document anyway.

send real time voice using udp

hi every body could you please help me . I write java code for sending string msg between client and server using udp socket . but I want to to send real time voice so could you please give some notes to do it
I can point you a little of the way, you probably would want to use the Real-time Transport Protocol (RTP), which is more or less the standard for sending audio or video real time over the net. However the implementation is not straight forward, and you should use a helper library like jlibrtp for the implementation. There is also a RTP packetizer in Java Media Framework (JMF), but you don't wanna go there....
UDP has no quality of service guarantee, so when sending your packets of data you will need to add some sort of order number to your data to detremine how to put the data back together. For example you could send 3 datagram packets in order from the server, yet the client may get them in a different order (2,1,3). Or it may not get one of them at all, in which case you either want it resent (doubtful) or simply ignore it and move on at some timeout.
Look into using Real Time Protocol RFC3550 (http://en.wikipedia.org/wiki/Real-time_Transport_Protocol)
as the transport over UDP. RTCP as the control over TCP.

Categories