Programming client-server with socket in multi-languages
Hi all,
I'm amateur programmer of, but I must developpe an network-application with socket which side-client write by VC++ and side-server write by QT4. I'm tried many ways, and they could realize themselves but the connection is not understanding thoroughly, so they couldn't receive data from other.
Have you some appropriate solutions?
one thing else, I don't know the way to improve this method to Fotune Server can receive data from Fotune Client, Can we make alterations this method? or Must create other. Please help me!
void Server::sendFortune(){
QByteArray block;
char bufff[256];
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << fortunes.at(qrand() % fortunes.size());
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
clientConnection->write(block);
clientConnection->disconnectFromHost();
}
Thanks for your replies>
Re: Programming client-server with socket in multi-languages
Don't use QDataStream. It's a serialization mechanism, not a general purpose binary stream. If you want to use it, you'd have to "teach" the other side how QDataStream encodes its data which would probably be an overkill using plain WinAPI.
Re: Programming client-server with socket in multi-languages
Thank for your reply, but you can speak more clair. With these examples, we can improve how to maintain the connection and can transfert data between them??
Re: Programming client-server with socket in multi-languages
Use QIODevice API for reading and writing to the socket instead of QDataStream.