LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data from telnet port 23 using ClientTCPRead.

I am using "ClientTCPRead" function to read the telnet port 23. My application acts as a client and I am requesting data from server.

It works fine for everything but I am not getting the full length of data as I am expecting. When server returns the data it adds a NULL after every line i.e., after every line with a CR there is a NULL too.
I can read this fine through the regular telnet programs say "Putty" but using "ClientTCPRead" function in CVI it only read the first line.

Any suggestion or comments on this will be greatly appreciated.

Thank you,
Hiren
Hiren Patel
0 Kudos
Message 1 of 4
(5,079 Views)
Hiren,

Are you aware that it is possible not to read the full data off buffer everytime? You may need to make subsequent reads based on the amount of data left in the buffer. Here is example code that does just this...

bytesToRead = messageSize;

while (bytesToRead > 0)

{

bytesRead = ClientTCPRead (connectionHandle, &buffer[messageSize - bytesToRead], bytesToRead, 0);

bytesToRead -= bytesRead;

}


Let me know if this helps! If this is not it, it is very possible the NULL is throwing off the reader. Do you have anyway of preventing your server from appending this NULL onto the string??

Have a great day!!

Allan S.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(5,079 Views)
Hi,

You can used extraputty to do that (send and received data through telnet protocole).
This addon of putty offered an Telnet API for TestStand.
The data received is not modify by extraputty.

I hope that can help you

extraputty.free.fr


Message Edited by Support on 02-04-2008 08:59 AM
0 Kudos
Message 3 of 4
(4,645 Views)
i know this thread is closed since 4 years but i can't resist... (and the solution may be interesting for many people)

the problem is simply that NULL bytes, also called NUL character are end-of-string delimiters. so, when printing/processing your buffer as a string, any function will ignore what lies beyond the first NUL character.

store the value returned by ClientTCPRead which represent the number of bytes read from the socket, then replace every NULL byte in your buffer by a printable character up to the number of bytes received, and guess what ? all your lines will automagically appear !


Message Edited by dummy_decoy on 01-30-2008 12:08 PM
0 Kudos
Message 4 of 4
(4,621 Views)