We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Greetings,
Intro: I am developing a TCP Server (TCP Passive Open) using LPC2364 (ARM7TDMI) using the old RL_TCPNet library. I need to send a string of ASCII data, which contains random characters with ASCII values ranging from 0 to 255 (ie. in hex 0x00 to 0xFF), over the TCP connection.
Issue: When I try to send a string which contains random ASCII characters, the data gets terminated with the NULL character in between and is partially transmitted.
In the RL_TCPNet library which I am using, I send the data in the following way,
unsigned char TCPSocket; unsigned char *TCPTxBuffer; unsigned short int TxBufferSize = 15; char data_buffer[20] = {'a','1','h','8','$','_','_','\0','-','-','k','e','i','l'}; main() { int i=0; for(i=0;i<15;i++) { TCPTxBuffer[i]=data_buffer[i]; printf("%c",TCPTxBuffer[i]); } //After TCP connection establishment tcp_send(TCPSocket, *TCPTxBuffer, TxBufferSize); //tcp_send(unsigned char, unsigned char *, unsigned short int) - Library function which is used to send data over TCP //TCPSocket - TCP Socket Identifier //TCPTxBuffer - TCP transmit buffer //TxBufferSize - TCP transmit buffer size. }
Ex:
Data to be sent : a1h8$__\0--keil Data Length: 15
Data received : a1h8$__
I understand this condition is obvious with C language. But, the printf statement which I have used in the code is able to print all the 15 characters as it has a for loop iteration count as 15.
Similarly, I have specified the data length(TxBufferSize) to be the actual length of the string (ie. 15). Then why does partial transmission takes places, still it gets terminated by NULL.
NOTE: The tcp_send function in the RL_TCPNet library is inaccessible and cannot be modified.
Requirement: In what ways could I transmit the full string of data over the TCP connection. Sending the whole data is crucial and preferably in ASCII format.
Kindly help me out in this regard. Thanks in advance.
Pratheep k said:a string which contains random ASCII characters, the data gets terminated with the NULL character
Of course it does - that is the defined behaviour of the string functions in the 'C' Standard!
If you want to send arbitrary data - which may contain NULs - then you cannot use 'C' string functions!
However, this has nothing specifically to do with TCP/IP.
Are you sure that the problem is actually in the TCP/IP, or just in your debug stuff?
for example:
for(i=0;i<15;i++) { TCPTxBuffer[i]=data_buffer[i]; printf("%c",TCPTxBuffer[i]); } //After TCP connection establishment tcp_send(TCPSocket, *TCPTxBuffer, TxBufferSize);
printf() is a 'C' string function - so it will stop printing at the first NUL - but that does not mean that the tcp_send() will not send the data beyond the NUL ...
Perhaps what you really want is something like:
for( i=0; i<15; i++ ) { TCPTxBuffer[i] = data_buffer[i]; printf( "%02X ", TCPTxBuffer[i] ); }
Hey Andy Neil, Thanks for replying.
"printf" in my code refers to a serial port output. I am printing these characters through an UART serial port for debug purpose and I am able to print all the characters in the buffer without being terminated by NULL. The data sent through TCP is monitored from another TCP server software, in which the data is terminated it with NULL (ie. partial transmission).
Which proves that the debug has no issues, only the "tcp_send" library function of the RL_TCPNet library terminates transmission of data from the buffer with a NULL. For which the reason being, the tcp_send library function must be written in such a way, for which we have no access.
Considering the fact that the tcp_send function cannot be modified, kindly suggest me a roundabout to somehow push the data through the TCP connection.
The tcp_send function accepts any data. The data are not processed, but transmitted as they are. So if you specified TxBufferSize = 15; the function should send 15 bytes (not characters). You can check this with the Wireshark.Are you sure the remote host is processing the data correctly? What if you had to use CR-LF characters instead of NULL termination?
Hey Franc Urbanc, Thanks for replying.
Franc Urbanc said:You can check this with the Wireshark.
I did the exercise. You were right. The remote host was only terminating the character set with NULL. The tcp_send function properly pushed out the 15 bytes of data. Issue resolved.
Thanks a lot for your support Franc Urbanc & Andy Neil...