Results 1 to 11 of 11

Thread: Sending string from QT client to Java server

  1. #1
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Sending string from QT client to Java server

    I am trying to send a string from my QT client to a Java server. I am able to get them connected, verified both with the QT and Java programs. However, I am not able to send a string over the socket, nothing gets passed to the server, can anybody help?

  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: Sending string from QT client to Java server

    You probably face encoding problems, but providing more details would help pinpoint the problem.

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

    seanmu13 (2nd July 2007)

  4. #3
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    Using a QTcpSocket I am able to successfully connect to localhost indicated by the socket state, I initialize a QTextSteam with the QIODevice being the socket, then I simply have:
    out << "someTextToSendToServer"; And when the Java server indicates that something was sent to it, it is just null. It's not a problem with the server because someone else was able to successfully send a string to the server with another program, but I am unable to contact them.

  5. #4
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    Do I have to use the write method in QIODevice?

  6. #5
    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: Sending string from QT client to Java server

    Was "another program" written in Java as well?

  7. #6
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    No it was written in C# I believe, so it didn't help much.

  8. #7
    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: Sending string from QT client to Java server

    Can we see some code of the Qt based client?

  9. #8
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    Qt Code:
    1. int port = 50000;
    2. QTcpSocket socket(this);
    3. connect(&socket,SIGNAL(connected()),this,SLOT(isConnected()));
    4. socket.connectToHost(QHostAddress::LocalHost,port,QIODevice::ReadWrite);
    5. socket.waitForConnected(1000);
    6. //socket.write((const char *)"sdfsdf",5);
    7. QTextStream out(&socket);
    8. out << "sample text" << endl;
    9. socket.disconnectFromHost();
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending string from QT client to Java server

    Quote Originally Posted by seanmu13 View Post
    QTextStream out(&socket);
    out << "sample text" << endl;
    socket.disconnectFromHost();
    How about calling waitForBytesWritten() before disconnecting and waitForDisconnected() after? If socket goes out of scope after a call to disconnectFromHost() it won't have any chance to send that data.
    Last edited by jacek; 2nd July 2007 at 21:51. Reason: typo

  11. The following user says thank you to jacek for this useful post:

    seanmu13 (3rd July 2007)

  12. #10
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    I'll try that and see how it goes. Thank you.

  13. #11
    Join Date
    Jun 2007
    Posts
    17
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending string from QT client to Java server

    Thank you so much Jacek! I've been working on that stuff for about a week now with no luck. Thanks again.

Similar Threads

  1. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23
  2. 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.