Sending data with QTcpSocket issue

  • I'm working on a client/server project with Qt to have a client and a server. Basically, I'm trying to get core functionality tested and working before building more on top of it (for a basic IM client for a project in school). I'm designing my message passing syntax so that I can automate the IM client a little bit.

    This is my readyRead() slot for the readyRead signal, server side. I'll mark the trouble spot with an all caps comment.

    @ if (stuff == "REG\n") //client would like to register. next message should be username
    {//need to add check to see if user exists
    socket->write("ACK"); //this is a hard ack that tells the client that it may write to the socket and be heard by the server.
    stuff.clear(); //verify that buffer is cleared.
    stuff=socket->readAll();//should have username followed by \n
    stuffText = stuff; //move it to a string so that I can manually remove the \n and then add it to the users list.
    stuffText.remove('\n'); //hopefully removes the \n
    //now to add to the user list, completing the register process.
    temp.setDescriptor(this->socketDescriptor);//temp user configured. time to add
    //clean up
    if(!socket->write(stuff))//THIS IS WHERE I'M HAVING TROUBLE
    qDebug() << "Didn't work.";
    //client has been added to the list. waiting for other data.

    At all-caps comment, everything up to that point has worked just fine. The client sends a REG request, the server responds (I know that the underlying protocol uses ACKs, I'm just sending back a known bit of text that I can test for). After the server response, my test client then sends the username it wishes to register, and the server gets it and parses it correctly, locks the shared memory location, writes, unlocks. Everything works well. Then I get to sending the ACK again, and though the server thinks it's sent it (at least, I think the criteria for the if should be right), but the client does not receive anything.

    Am I doing something wrong?

    Thank for any help,

  • Hi seanr8. What does your client-side look like? If your server is having a hard time sending data across a TCP socket it generally means that the connection was broken for some reason.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.