[Qt-interest] QTcpSocket.

Shabd Swarup V shabd at cadence.com
Mon Mar 2 13:58:23 CET 2009


Hi,

 

I am trying to read data off a socket on localhost and I'm using netcat
(nc) to simulate the server and to send messages on a particular socket.

 

Following is the code snippet:

/**

* Thread to detect socket data.

 *

 */

void Communicator::run()

{

        socket = new QTcpSocket();

        std::cout<<"Trying to connect to socket...\n";

        socket->connectToHost("localhost", 1234);

        if (socket->waitForConnected(3000)){

                std::cout<<"*****connected*****\n";

                connect(socket, SIGNAL(readyRead()), this,
SLOT(readSocketData()));

        }

 

}

 

 

/**

 * Read data available on the socket.

 */

void Communicator::readSocketData()

{

        std::cout<<"******reading socket data**********\n";

        QByteArray buf = socket->readAll();

        std::cout<<"Buffer value == ";

        for (int i=0;i<buf.size();i++)

        {

                std::cout<<buf.at(i);

        }

        std::cout<<std::endl;

        return;

}

 

 

Through this code, I am unable to capture the data from the socket, even
though the connection is made. Please correct me.

 

Thanks,

Shabd

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090302/3173f7f8/attachment.html 


More information about the Qt-interest-old mailing list