Note that there are some explanatory texts on larger screens.

plurals
  1. POTCP socket communications are being corrupted
    primarykey
    data
    text
    <p>I am trying to use a TCP server and connect to it with a QTcpSocket client. Most of the time, the server and client happen to be on the same machine, but this is not a requirement. What I am trying to do is transfer a file from a running multithreaded process to a GUI that wants to share information used by both the server and the client.</p> <p>The connect, etc seems to be just fine. In fact, the code appeared to work perfectly for a long time, but now that I am running it on different hardware, and on Ubuntu 12.04 instead of 10.04, I am occasionally getting embedded stray bytes in the received code--usually (but not always) nulls. I cant figure out whats wrong, and would welcome any advice.</p> <p>Here is portion of the server that reads my file and sends the bytes to the connected client:</p> <pre><code>int fileSize; printf(" about to open the file\n"); ini_fd = fopen (rov_ini_file_name, "r"); if(!ini_fd){ break; } fseek(ini_fd,0,SEEK_END); fileSize = ftell(ini_fd); fseek(ini_fd,0,SEEK_SET); int totalBytesSent =0; int line = 0; int len; while (!feof (ini_fd)) { ch = fgets (&amp;(my_line[0]), MAX_CHARACTER_COUNT - 1, ini_fd); if (ch){ len = strlen(&amp;(my_line[0])); bytes_sent = sendto(tio.my_tio_port_table_entry.to_sock, &amp;(my_line[0]), len, 0, (struct sockaddr *) (&amp;(tio.my_tio_port_table_entry.ToAddr)), sizeof (tio.my_tio_port_table_entry.ToAddr)); totalBytesSent += bytes_sent; line++; //printf(" line %d bytes sent = %d total bytes = %d\n",line,bytes_sent,totalBytesSent); } } len = sprintf(&amp;(my_line[0]),"END_OF_INI_FILE"); bytes_sent = sendto(tio.my_tio_port_table_entry.to_sock, &amp;(my_line[0]), len, 0, (struct sockaddr *) (&amp;(tio.my_tio_port_table_entry.ToAddr)), sizeof (tio.my_tio_port_table_entry.ToAddr)); tio.my_tio_port_table_entry.connected = FALSE; break; </code></pre> <p>Here is where I read the data being sent. This is the slot connected to the readyRead signal</p> <pre><code> void AlvGUI::readIniFromServer() { QByteArray inArray(iniClient-&gt;bytesAvailable(),0); if(!iniStarted) { tempIniFile = new QTemporaryFile; if(tempIniFile-&gt;open()) { iniStarted = true; } else { // error should be here! } } int bytesRead = iniClient-&gt;read(inArray.data(),inArray.size()); int endLoc = inArray.lastIndexOf("END_OF_INI_FILE"); if(-1 != endLoc) { inArray.chop(endLoc); bytesRead = endLoc; iniFinished = true; } tempIniFile-&gt;write(inArray.data(),bytesRead); if(iniFinished) { tempIniFile-&gt;flush(); tempIniFile-&gt;close(); iniFile.close_ini(); char *theTempFile = strdup((char *)tempIniFile-&gt;fileName().toAscii().data()); iniFile.open_ini(theTempFile); gotIni = true; iniRequestTimer-&gt;stop(); makeGui(); free(theTempFile); hotelSetup = true; iniClient-&gt;abort(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload