[Qt-interest] Alternative for bind() in TCP sockets

Anisha Kaul anisha.kaul at hitechroboticsystemz.com
Tue Jan 25 07:29:33 CET 2011


Thanks for replying, Saryesh,


// This is in the constructor---------------------------------
tcpServer = new QTcpServer();
if (!tcpServer->listen())
{
   close(0);
}
bool h = connect (tcpServer, SIGNAL(newConnection()), this, SLOT(myNewConnection()));
cout << "\nh: \n" << h; // prints 1

// The SLOT----------------------------------------------------
void QTcpSocketUtility :: myNewConnection ()
{
   objTcpSocket = tcpServer->nextPendingConnection ();
   bool h = connect (objTcpSocket, SIGNAL(newConnection()), objTcpSocket, SLOT(myNewConnection()));
   cout << "\nh: \n" << h;   
}

// Create socket function ------------------------------------
if (objTcpSocket == NULL)
{
   objTcpSocket = new QTcpSocket();
   cout << objTcpSocket->isOpen (); // prints 0

   objTcpSocket->setSocketOption (QAbstractSocket :: KeepAliveOption, QVariant (1));
   objTcpSocket->setSocketOption (QAbstractSocket :: LowDelayOption, QVariant (1));
}

// Receive Message function-------------------------------------
   cout << objTcpSocket->isOpen (); // prints 0
   returnValReadDatagram = objTcpSocket->read (receivedData, 0);
// returns -1



On Tue, 2011-01-25 at 11:18 +0530, sarvesh saran wrote:
> Hi Anisha,
> 
> 
> Can you show a snippet of your code ( the connections, the read call
> etc) ? That will really help people in answering your questions..



-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India







More information about the Qt-interest-old mailing list