saman_artorious
19th June 2013, 07:08
I wrote this code to connect to the ip address of my own machine. bind returns true, though connect wouldn't prompt anything. I also run another program, using same ip and port but these two do not connect.
void UDP::UDPtInit()
{
socketPort = PORT;
udpsocket = new QUdpSocket(this);
if(!udpsocket->bind(QHostAddress("192.168.111.1"),socketPort))
{
qDebug() << "true";
}
else
{
qDebug() << "false";
}
connect(udpsocket,SIGNAL(readyRead()),this,SLOT(re adState()));
connect(udpsocket,SIGNAL(connected()),this,SLOT(so cketConnected()));
connect(udpsocket,SIGNAL(error(QAbstractSocket::So cketError)),this,SLOT(socketError(QAbstractSocket: :SocketError)));
emit clientActive(true);
}
void UDP::socketError( QAbstractSocket::SocketError )
{
qDebug() << "UDPCLIENT ERROR: "<< udpsocket->errorString();
}
void UDP::socketConnected()
{
qDebug() << "UDPCLIENT : Socket connected!";
emit clientLogMessage(QString("UDPCLIENT : Connected !"));
}
void UDP::UDPtInit()
{
socketPort = PORT;
udpsocket = new QUdpSocket(this);
if(!udpsocket->bind(QHostAddress("192.168.111.1"),socketPort))
{
qDebug() << "true";
}
else
{
qDebug() << "false";
}
connect(udpsocket,SIGNAL(readyRead()),this,SLOT(re adState()));
connect(udpsocket,SIGNAL(connected()),this,SLOT(so cketConnected()));
connect(udpsocket,SIGNAL(error(QAbstractSocket::So cketError)),this,SLOT(socketError(QAbstractSocket: :SocketError)));
emit clientActive(true);
}
void UDP::socketError( QAbstractSocket::SocketError )
{
qDebug() << "UDPCLIENT ERROR: "<< udpsocket->errorString();
}
void UDP::socketConnected()
{
qDebug() << "UDPCLIENT : Socket connected!";
emit clientLogMessage(QString("UDPCLIENT : Connected !"));
}