Hi,
I have a client as well as a server.I want to send .csv file to server line by line.I can do read the file line by line and write to the socket.But the problem is that server not receiving data line by line.it accept data after total reading of client's file.
I want client read a LINE and send it to server and server read that line.Again client read next line and send to server.
Any help???????
My client code like this....

client.h
Qt Code:
  1. class Client : public QObject
  2. {
  3. Q_OBJECT
  4. public:
  5. Client(QObject* parent = 0);
  6. ~Client();
  7. void start(QString address, quint16 port);
  8. // void Read(QString filename);
  9.  
  10. public slots:
  11. void readData();
  12. void sendData();
  13. private:
  14. QTcpSocket client;
  15. QString line;
  16. char *c_str2;
  17.  
  18. int LENGTH;
  19. };
  20.  
  21.  
  22. #endif // CLIENT_H
To copy to clipboard, switch view to plain text mode 

client.cpp
Qt Code:
  1. Client::Client(QObject* parent): QObject(parent)
  2. {
  3. connect(&client, SIGNAL(connected()),this, SLOT(readData()),Qt::DirectConnection);
  4. connect(&client, SIGNAL(connected()),this, SLOT(sendData()),Qt::DirectConnection);
  5. LENGTH =8;
  6.  
  7. }
  8.  
  9. Client::~Client()
  10. {
  11. client.close();
  12. }
  13.  
  14. void Client::start(QString address, quint16 port)
  15. {
  16. QHostAddress addr(address);
  17. client.connectToHost(addr, port);
  18. }
  19. void Client::readData()
  20. {
  21. QString mfilename ="/home/client2/Desktop/akde.csv";
  22.  
  23. //Read(mfilename);
  24. // QByteArray ba = line.toLocal8Bit();
  25. // c_str2 = ba.data();
  26. // client.write(c_str2,5000);
  27. QFile mfile(mfilename);
  28.  
  29. //if(!mfile.open(QFile::ReadOnly | QFile::Text))
  30. if(mfile.open(QIODevice::ReadOnly | QIODevice::Text))
  31. {
  32. // qDebug() << "Could Not Open File For Reading!";
  33. // return;
  34. //}
  35. QTextStream in(&mfile);
  36.  
  37. //QByteArray ba;
  38. while (!in.atEnd()) {
  39.  
  40. line = in.readLine();
  41. QByteArray ba = line.toLocal8Bit();
  42. c_str2 = ba.data();
  43. client.write(c_str2);
  44. sleep(1);
  45.  
  46.  
  47. qDebug() << line;
  48.  
  49. }
  50.  
  51. mfile.close();
  52. }
  53. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <client.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QCoreApplication a(argc, argv);
  7. Client client;
  8. client.start("112.165.1.2", 7350);
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode