This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sending NULL character ('\0') over a TCP connection

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.

Parents
  • 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.

Reply
  • 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.

Children
  • 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.

    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...