Showing results for 
Search instead for 
Did you mean: 

TCP Read String

Go to solution



I am tryting to modify TCP such that it only outputs single string instead of concatenated strings. At the moment program is just concatenating strings.  I

am looking to get one whole latest string at the port. So when it receives string 2 it should flush the string 1. 


This is string1. (I have to perform some string functions on it and get soem result from here)

This is string2.( So when I receive this string 2, string 1 must have been flushed and string2 is only left behind so that I can perform same operations on this string also.)


I have tried but not successful.

0 Kudos
Message 1 of 8

I'm sorry, I don't  think I understand what you are asking.  If you only want the receiving end to display one line at a time, why not just remove "Concatenate Strings" and wire the output of match pattern (used to remove the end-of-transmission character) directly to the string indicator?


TCP doesn't necessarily send exactly one string at a time; if you send multiple short strings in quick succession, TCP by default will combine them into a single transmission and you'll have to separate the strings yourself by searching for an end-of-line character.

0 Kudos
Message 2 of 8

Yeah I only need one string at a time. But I couldnt understand wht does /04 means split string function. Can you elaborate it more plz how to implement it.I m still in doubt because by string I meanone complete whole line i.e "this is website of National Instruments."



0 Kudos
Message 3 of 8

The \xx notation (when the \ codes display is turned on) tells LabVIEW to interpret the xx as an ASCII code.  You can look up ASCII codes in the help; in this case, 04 is the little-used EOT (End of Transmission).  It is sent only when the Stop button is pressed and signals that the sending side is finished sending data; when the receiving side receives that character it exits as well.


When you read data from a TCP/IP connection, you read a specific number of bytes (characters), not an entire line at once.  There are several common ways to indicate the end of a string, all of which are detailed in the LabVIEW help: you can send fixed-size strings, you can prepend the string length and then read that number of bytes, or you can put a terminating character (such as a newline) at the end of each string.  You need to use one of these methods because otherwise when you read data you could receive more than one string, or an incomplete string, depending on how much data you requested and how much has been sent.

Message 4 of 8

There is CRLF at the end of string. So can you please help me how shd I change the program to receive the complete string.

0 Kudos
Message 5 of 8
I have managed to extract the string1. But now I dont knw how to extract remaining strings because if I put while loop around it. Then it stays in while loop for ever.
0 Kudos
Message 6 of 8

Don't use a local variable for the offset - that's what a shift register is for, to store a value from one iteration of a loop to the next.  However, you don't need to store the offset at all.


Have you debugged your code, using probes or execution highlighting (the lightbulb icon in the toolbar)?  The offset being returned by Match String is the location of your newline character.  The first iteration of the loop finds the newline properly, the second iteration then starts looking at the exact offset of the newline, finds it immediately, and never returns the next string.  You don't want to simply add 1 to the offset because then the first iteration you'll get string1, the next iteration you'll get string1 + string2, etc.  Instead, once you split out string1, only save the remainder (remove the newline, then save anything that follows it) in the shift register to be processed the next loop iteration.

0 Kudos
Message 7 of 8
Accepted by topic author arrowminds

Thx for your help but I have found more easy convenient solution. I have just changed the mode of TCP Read from Standard to CRLF.And Now I can get single complete strings directly from port




0 Kudos
Message 8 of 8