I've noticed that you send (upto) 500 chars, and you append a '\n' to the end of your string. But there is no terminating ASCII NULL.
When you receive your characters, you are (providing no error), sending the contents of the buffer (buf) to your UIR Panel. Since there is no ASCII_NULL it might print garbage.
If you initialise the TX buffer with all ASCII_NULLS, and then append one to each string before sending, see what effect that has.
Since you are Tx'ing 500 characters (unless there is an ASCII NULL in there somewhere), your receive function will Rx all 500 and the function continues, but, assuming your only transmitt 400 because, your RX function will wait for the timeout period (1000 in your case) until proceding. Since you are acting on TCP_DataReady,
you could lower this value down to 100 or less, and it will respond to as many characters as you send it.
When you calculate the string length of your buffer to send, it does not, or might not find the terminating ASCII_NULL, so the number of characters actually transmitted may be differnent to the number in your buffer.
Other than that, its basically the same as I have.