0
votes

I am developing an application where i need to send message from client to server and notify server if there are changes in files on client. I am using QTcpServer and QTcpSocket class in Qt ..I am writing on socket and reading from socket on server side but my read fails.

Can i know how to post a message to server. I need implementation in Qt and C++..

Thanks in advance

Code on client side for writing :

QByteArray block; QDataStream out(&block, QIODevice::ReadWrite); out.setVersion(QDataStream::Qt_4_0);//statusLabel->setText(fortunes); getFortuneButton->setEnabled(true); //! [4] //! [6] out << (quint16)0; out << fortunes.at(qrand() % fortunes.size()); out.device()->seek(0); out << (quint16)(block.size() - sizeof(quint16)); //! [6] //! [7]

    tcpSocket->connectToHost("172.31.28.140",1331,QIODevice::ReadWrite);
    qint64 t = tcpSocket->write(block);

Code on server side: QDataStream in(clientConnection); in.setVersion(QDataStream::Qt_4_0); QString nextFortune; in >> nextFortune; statusLabel->setText(nextFortune); qDebug()<canReadLine(); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));

1
We probably need a good bit more information to hazard a useful guess. Like, what code are you using to send/receive?Andrew Barber
Please re-format your code properly. This is hardly readable.BastiBen

1 Answers

0
votes

There is an example of client-server application coming with QT. Take a look at it

PS: format your text