I noticed both the QUdpSocket::readDatagram() and QUdpSocket::writeDatagram() functions accept char *'s as parameters.

On the readDatagram side you're supposed to pass in a length parameter, where I've been putting a constant: 1024.

But when I send char *'s and then receive them, I get these trailing characters. For example when I send: "CONTAIN_STRANGEMATERIALFACILITY"

I get: "CONTAIN_STRANGEMATERIALFACILITY¿äî"

I've tried making the last character '0' and NULL, and newline (10), but they don't work.

My server code:
Qt Code:
  1. QHostAddress the_address;
  2. quint16 the_port = 0;
  3. char char_incoming[1024];
  4.  
  5. readDatagram( (char *)char_incoming, 1024, &the_address, &the_port );
  6. cout << "incoming string is: " << char_incoming << endl;
To copy to clipboard, switch view to plain text mode 

And my client code:
Qt Code:
  1. QString request_string( "CONTAIN_STRANGEMATERIALFACILITY" );
  2. char buffer[512];
  3. int buffer_length = snprintf( buffer, sizeof buffer, request_string.toAscii().data() );
  4. cout << "buffer_length = " << buffer_length << endl;
  5.  
  6. //buffer[ buffer_length ] = 10; // tried this as well, just puts in a newline
  7. //buffer_length++;
  8.  
  9. int success = writeDatagram( buffer, host_address, port_number );
To copy to clipboard, switch view to plain text mode 

And then on the server side I get a bunch of junk.

I'm not sure how I can know the size before I read it.