For the moment, I'm doing all this code in the same app and communicating over localhost (127.0.0.1). The first toWrite line saying hello world and the Port Number works, but my longer file gets truncated at 8192 characters. Its including the length of the thing to write, so I'm not sure what I'm doing wrong. I'm not new to Qt but I am new to this particular process.

The idea here is that a client would send a file (which contains print job data) over the network through the specified port to the server's client where it will receive the data and do stuff with it, like write to a file, assign it to a printer on the server, etc.

Client Sends the data:
Qt Code:
  1. void Client::startTransfer() {
  2. QByteArray toWrite;// = QByteArray("Hello, world (Port: " + QByteArray::number(PORTNUMBER) + ")");
  3. //
  4. QFile file("./PrintJobs/exampleprintjob");
  5. if(!file.open(QIODevice::ReadOnly)) {
  6. QMessageBox::information(0, "error", file.errorString());
  7. }
  8. QTextStream in(&file);
  9. QStringList lines;
  10. while(!in.atEnd()) { lines.append(in.readLine()); }
  11. file.close();
  12. QString file2 = "";
  13. foreach(QString line, lines) { file2 += line + "\r\n"; }
  14. toWrite = file2.toLatin1();
  15. //
  16. client.write(toWrite,toWrite.length()); // length = 188,673 characters, 184 KB file size
  17. //
  18. client.flush();
  19. }
To copy to clipboard, switch view to plain text mode 
Server reads the data:
Qt Code:
  1. Server::Server(QObject * parent): QObject(parent) {
  2. connect(&server, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
  3. server.listen(QHostAddress::Any, PORTNUMBER);
  4. }
  5. void Server::acceptConnection() {
  6. client = server.nextPendingConnection();
  7. connect(client, SIGNAL(readyRead()), this, SLOT(startRead()));
  8. }
  9. void Server::startRead() {
  10. QByteArray buffer;
  11. buffer = client->read(client->bytesAvailable());
  12. emit readFromListening(buffer);
  13. client->close();
  14. }
To copy to clipboard, switch view to plain text mode