Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period.

18 vues (au cours des 30 derniers jours)
Actually my project is Encryption of message at the sender site and Decryption at the receiver side. There is no problem at the sender side, but at the receiver side it is creating issues. The normal code for encryption and decryption is perfect, but the problem arises with the tcpip at the receiver. The decryption of the message at the sender side is not same when using the tcpip, but without using the tcpip the decryption is perfect. The message encrypted appears perfectly at the receiver side but problem arises afterwards as the decryption is not perfect and throwing error as unsuccessful read.
at sender:
t=tcpip('0.0.0.0',30000,'NetworkRole','Server');
t.OutputBufferSize=5000;
fopen(t);
fprintf(t,'%s\n',out3);
fwrite(t,h);
fwrite(t,st);
at receiver:
t=tcpip('LocalHost',30000,'NetworkRole','Client','TimeOut',3);
t.InputBufferSize=5000;
fopen(t);
nam=fscanf(t)
b1=fread(t);
please help me with this.

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Fév 2020
Rules for Completing a Binary Read Operation
A read operation with fread blocks access to the MATLAB Command Window until
  • The specified number of values is read. For UDP objects, DatagramTerminateMode must be off.
  • The time specified by the Timeout property passes.
  • A datagram is received (for UDP objects only when DatagramTerminateMode is on).
  • The input buffer is filled.
  • The EOI line is asserted (GPIB and VXI instruments only).
  • The EOSCharCode is received (GPIB and VXI instruments only).
The "specified number of values" by default is the number that fill the input buffer.
You are not using UDP so datagram does not matter.
You are not using GPIB or VXI so EOl and EOSCharCode are not relevant.
So what is left is Timeout (what you are getting), or the input buffer being filled.
You have set the input buffer size to 5000.
What we are not given enough information to know is whether your output value h happens to be 5000 bytes. If it is less, then because you only write h (after the text line), the reader would sit waiting until timeout.
There are basically five ways of using TCP:
  1. don't send binary data (represent numbers by text) and send line terminators; or
  2. encode variable length binary data in forms that is guaranteed not to have whatever terminator you choose, and send that and the terminator to end the packet; or
  3. never send variable-length binary data: use a protocol that uses a fixed length of binary data at every point, and reads only that much data. Terminator should be off for this purpose; or
  4. only send variable length binary data as the last part of the conversation, and close down the socket to signal to the other end that there is no more data to be received. Terminator should be off for this purpose; or
  5. do not send binary data whose length is not known to the receiver. Instead, use a protocol that transmits the size first (possibly in binary) followed by the variable length data. The receiver reads the fixed length size, and uses that to adjust the information about how much binary data to read. Terminator should be off for this purpose.
  3 commentaires
Walter Roberson
Walter Roberson le 13 Fév 2020
Your code is badly in need of a rewrite.
Create a cell array of character vectors, each representing one of the items to match, in the order you want them to be matched. Then use ismember() of the data to be matched to that cell array, using the second output of the function to get an index into the list. Convert the index to binary to get your tempch .
On the reverse end, convert your tempch binary to a decimal number and use that to index the cell array of matched characters.
No more switch, no more long long if/if chains.
Samuel Gray
Samuel Gray le 18 Mar 2021
Modifié(e) : Samuel Gray le 18 Mar 2021
"Your code is badly in need of a rewrite."
LOL

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by