PDA

View Full Version : QTCPSockets



Thunder
6th August 2008, 18:19
I am having trouble with using TCP sockets in QT. I have opened a socket for reading and writing and when it tries to write I get the message "QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectState" over and over. Before I write I check what state it is in and it is showing QAbstractState::Connected which is value 3 being printed out. How come it is having trouble writing on the socket. Here is the code I am using for wrting on the socket. I am writing in Windows and it runs ok, then I bring the code over to CentOS and it compiles ok but when I run the application it runs into this problem. Any help would be appreciated.


.
.
.
tcpSocket1 = new QTcpSocket();
tcpSocket1->connectToHost("192.168.0.101", 800, QIODevice::ReadWrite);
if(tcpSocket1->socketDescriptor() > 0)
tcpSocket = tcpSocket1;

if (!tcpSocket->waitForConnected(Timeout))
return;

connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(read_data()));
connect( tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
.
.
.

void Common::send_sock_data_1(int G_sock_data_len)
{
int byte_send = 0;

if(tcpSocket == NULL) return;
qDebug("TCP socket is %d\n", tcpSocket->state());
if(tcpSocket->state() != QAbstractSocket::ConnectedState ) return;

if ( tcpSocket->isValid() )
{
byte_send = tcpSocket->write(G_sock_data_1, G_sock_data_len);
.
.
.