Matlab UDP randomly missing data
Mostrar comentarios más antiguos
I have a test I would like to run for many hours. It is very simple, I send a command to my network device and expect an acknowledge message back. I utilize fwrite and fread to send/receive these messages.
Sometimes when I set this test to run overnight I find the next morning that the test failed to receive an acknowledge. The response I expect is only 4 bytes long: 0x01; 0x7F; 0x06; 0x10.
I can look at my UDP socket after this failure and I noticed in the Read/Write state there were "BytesAvailable". Looking here I found 3 bytes: 0x7F; 0x06; 0x10. It appears that the socket failed to read the first byte.
Like I said before, this happens very intermittently and I haven't found a way to reliably reproduce.
Does anyone know what could be causing this, is this a known issue, or maybe a way to work around this issue? Thanks for any help!
4 comentarios
Walter Roberson
el 6 de Jun. de 2013
Are all 4 bytes stored in the same packet? Or are those separate packets?
With UDP you need to assume that whole packets might go missing without a trace, and you should expect that any one packet might have its bytes corrupted (not in modern ethernets but possible still in wireless).
However, if the packet is received then leading bytes of the payload should not be missing (in old ethernets, trailing bytes could go missing due to faulty equipment.)
In your situation, is it possible that all 4 bytes were received in the socket, but that one of those bytes has already been read out of the buffer?
Marshall
el 10 de Jun. de 2013
Marshall
el 10 de Jun. de 2013
Respuestas (1)
Walter Roberson
el 10 de Jun. de 2013
0 votos
datagram terminate mode means that the data becomes available with each datagram instead of waiting for a terminator such as linefeed. But becomes available means it goes into the buffer. If you only ask to fread() a single byte then the remaining bytes stay in the buffer.
You can ask to read (object).BytesAvailable bytes from (object) and then use the bytes from where you store them instead of reading as-you-need-them.
1 comentario
Marshall
el 10 de Jun. de 2013
Categorías
Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!