Hi.
I've writing TcpServer app in Qt and client in avr32 processor, but i got problem with server. My server should be multi-threaded, each of client on other thread. My problem is:
When I've connected newConnection() signal with this slot:
void CTcpServer::incomingConnection(int socketDescriptor)
{
//IF there are still empty slots
if(numOfClients < MAX_CLIENTS)
{
//Check which one is empty
for(int i=0; i<MAX_CLIENTS; i++)
{
//Empty slot found
if( 0 == clients[i])
{
//got socket
clients[i] = new CTargetThread(socketDescriptor,this,socket);
connect(clients[i], SIGNAL(finished()), clients[i], SLOT(deleteLater()));
clients[i]->start();
//Client counter indicate how much clients are connected to server
numOfClients++;
break;
}
}
}
}
void CTcpServer::incomingConnection(int socketDescriptor)
{
//IF there are still empty slots
if(numOfClients < MAX_CLIENTS)
{
//Check which one is empty
for(int i=0; i<MAX_CLIENTS; i++)
{
//Empty slot found
if( 0 == clients[i])
{
//got socket
clients[i] = new CTargetThread(socketDescriptor,this,socket);
connect(clients[i], SIGNAL(finished()), clients[i], SLOT(deleteLater()));
clients[i]->start();
//Client counter indicate how much clients are connected to server
numOfClients++;
break;
}
}
}
}
To copy to clipboard, switch view to plain text mode
it simply check is a client slot aviable and runs thread for connected client.
and there is CTargetThreads run method:
void CTargetThread::run()
{
if (!socket->setSocketDescriptor(iSocketDescriptor)) {
//emit error(tcpSocket.error());
qDebug("setSocketDescriptor failed");
return;
}
qDebug("Socket granted");
while(1)
{
socket->write("Sample message");
msleep(50);
}
socket->disconnectFromHost();
socket->waitForDisconnected();
}
void CTargetThread::run()
{
socket=new QTcpSocket();
if (!socket->setSocketDescriptor(iSocketDescriptor)) {
//emit error(tcpSocket.error());
qDebug("setSocketDescriptor failed");
return;
}
qDebug("Socket granted");
while(1)
{
socket->write("Sample message");
msleep(50);
}
socket->disconnectFromHost();
socket->waitForDisconnected();
}
To copy to clipboard, switch view to plain text mode
And problem is:
my packet with "sample message" doesn't seems to be send, I use WireShark to look up for packets, and it does not shows that packet.
Thread is created normally, setSocketDescriptor returns false, so it success, and when i write something, it just not working.
When I write something on client(avr32) side, it can't be readed in thread, but i see in WireShark, that this packet have been sent.
please, help me
Bookmarks