Results 1 to 4 of 4

Thread: Programming client-server with socket in multi-languages

  1. #1
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt4

    Default 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>
    Last edited by philiptine; 6th September 2007 at 05:36. Reason: reformatted to look better

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  3. #3
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt4

    Default 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??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Programming client-server with socket in multi-languages

    Use QIODevice API for reading and writing to the socket instead of QDataStream.

  5. The following user says thank you to wysota for this useful post:

    philiptine (7th September 2007)

Similar Threads

  1. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.