Page 3 of 3 FirstFirst 123
Results 41 to 57 of 57

Thread: QSslSocket vs QTcpSocket problem

  1. #41
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    It won't be enough if I just do sth like this?:
    Qt Code:
    1. QDataStream out(&block, QIODevice::WriteOnly);
    2. //serverfiles is a QStringList
    3. out << (out,serverfiles);
    4. serverSocket->write(block);
    To copy to clipboard, switch view to plain text mode 

    This code is in slot which starts thx to encrypted signal.

  2. #42
    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: QSslSocket vs QTcpSocket problem

    No, not really. You are streaming in a QStringList and reading back 4 bytes assembled into integer and an anonymous block of data. How do you expect it to work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #43
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    Becouse I still can't see how it should work this, I don't understand how to adjust the code at the server side(I am sending QSringList which has paths for the client becouse every file which will be received by client should be stored with one path from the received list). I still can't get a rid of this way of thinking about the problem, which was presented in the first post. I wrote it and understand it perfectlly. I still see it like this:

    -server sends size of "thing" that will be sended in a second
    -client receives size of "thing"(client know that firstly it will get the size)
    -server sends the "thing"
    -client knows that the "thing" will be now received and thx to the size(that it has just received), client knows how big the "thing" will be.

  4. #44
    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: QSslSocket vs QTcpSocket problem

    Maybe you see it like this but you didn't implement it like this.
    -server sends size of "thing" that will be sended in a second
    -server sends the "thing"
    Qt Code:
    1. QDataStream out(&block, QIODevice::WriteOnly);
    2. //serverfiles is a QStringList
    3. out << (out,serverfiles);
    4. serverSocket->write(block);
    To copy to clipboard, switch view to plain text mode 
    Doesn't seem equivalent to me.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #45
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    ups it should look like this
    Qt Code:
    1. out << (out, serverfiles.size());
    2. serverSocket->write(block);
    3. block.clear();
    4. out << (out, serverfiles);
    5. serverSocket->write(block);
    6. block.clear();
    To copy to clipboard, switch view to plain text mode 

    This:
    Qt Code:
    1. out << (out, serverfiles);
    To copy to clipboard, switch view to plain text mode 
    I've also found it in Qt Assistant-as a way of sending QtStringList in right way.

    Generally as you can see when client connects to the server it always looks like this;
    server sends QStringList
    client sends his QStringList
    server sends files

    That is way my first code wasn't random in its simple construction.

  6. #46
    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: QSslSocket vs QTcpSocket problem

    Well, the reading side is still different.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #47
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    Could you show me how the sending side should look like(I can't figure it out)-will it be universal for sending variables such as QStringList and files?

  8. #48
    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: QSslSocket vs QTcpSocket problem

    The point is the same protocol needs to be used on both sides. If I talk to you in Roman Latin and you only understand Polish there is just no way we will understand each other even if we talk about the same things. Both sides need to communicate in the same "language" or at least they have to agree first on languages they understand. If you're using QDataStream on the transmiting side, the receiver has to use QDataStream as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #49
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    I still don't understand why waitforReadyRead doesn't work in slot here with SSL slot, as far as I am concerned when I use it in slot that was onced triggered, for example:

    Qt Code:
    1. while(serverSocket->bytesAvailable() == 0)
    2. {
    3. QTextStream(stdout) <<"Waiting for confirmation" <<endl;
    4. }
    To copy to clipboard, switch view to plain text mode 
    it should make the program to stop and do the while loop until the readyRead signal is emitted and then the program continue its work. It is very strange that the signal doesn't show up here. At the client side I just did clientSocket->write("Confirmation") and it returned 12 bytes written to the socket, but at the server side still nothing. WaitforReadyRead isn't working as it should? And by the way I am from Poland so I could also understand You

  10. #50
    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: QSslSocket vs QTcpSocket problem

    Quote Originally Posted by camol View Post
    I still don't understand why waitforReadyRead doesn't work in slot here with SSL slot
    Ok, enough for me. I already told you why this happens in the very beginning. I'm not going to repeat myself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #51
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    I think I've finally got it, sorry Wysota for me childish behaviour. I have one question is possible some how to check what kind of data type the QByteArray buffer is carring? I am expecting three types: QStringList, QString,, and the exact date which i will write to the file? I tried using QByteArray::contains("STORAGE"), becouse I know that if it will be QStringList, each QString in that QStringList will have "STORAGE" somewhere. But this is not actually working.

    EDIT: when in do contains("S") it sees the single char but only one at time.
    Last edited by camol; 17th March 2011 at 14:12.

  12. #52
    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: QSslSocket vs QTcpSocket problem

    Quote Originally Posted by camol View Post
    I have one question is possible some how to check what kind of data type the QByteArray buffer is carring? I am expecting three types: QStringList, QString,, and the exact date which i will write to the file?
    The data is an opaque blob as far as tcp is concerned. You might have one byte of data or one gigabyte of data there. The only way to detect what data is inside is if you inject such information when sending the data and then you perform a scan to detect such marks on the receiving end.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #53
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    I thought that it would be as easy as I thought. However, for example if I put some mark at the beginning of the QByteArray which I am sending at the server side, when I get it using client:do I have to cut off the "mark" from the beginning, becouse it will affect for example the file which I will create using this received QByteArray and the file won't be the same as the file from the server side?

  14. #54
    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: QSslSocket vs QTcpSocket problem

    You can do whatever you want. The important part is to do the same (or rather "matching") things on both ends of the wire. If you add something to the stream while sending then you have to remove it while receiving.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    camol (18th March 2011)

  16. #55
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    Big thanks

  17. #56
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket vs QTcpSocket problem

    I've encountered a strange problem. I've rewritten my app in the signal-slot way, and everything works like a charm but only at the first time. The server side is louched the client connects, and my outputs from server and client are showing that everytning works like it should but when I connect to the lounched server with client once more, the server some how is sending each files about 2 times, but I can't figure why. I made many new signals for example send_f() which is emitted only when server gets confirmation from client. But as I said after second client louching it looks like this signal is emited twice but it should be impossible considering that first louchning is always perfect. When I fire the client for third time the connection isn't even established.

    EDIT:
    SOLVED, I was connecting this signal in wrong place. THX WYSOTA for quick reply
    Last edited by camol; 24th March 2011 at 15:40.

  18. #57
    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: QSslSocket vs QTcpSocket problem

    Most probably you are performing two connect() calls instead of one. Or you have some stale data somewhere in some list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. problem with QTcpSocket
    By Fallen_ in forum Qt Programming
    Replies: 10
    Last Post: 28th November 2010, 12:03
  2. QSslSocket - problem with connecting to the server
    By kremuwa in forum Qt Programming
    Replies: 9
    Last Post: 26th August 2010, 15:40
  3. Problem in QTcpSocket
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2008, 13:12
  4. QSslSocket problem
    By The Storm in forum Qt Programming
    Replies: 5
    Last Post: 23rd March 2008, 13:58
  5. problem with QTcpSocket
    By SuperSonik in forum Qt Programming
    Replies: 8
    Last Post: 31st January 2007, 17:00

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.