thanks jacek for your reply.
Actually, my application runs in threads. Client as well as Server. First of all, sorry for posting freakingly long. I want to complete it by myself but i am stumped.
Client side inside thread
void CEthernet::DoWork() // run()
{
Lock();
if(m_pSocket->waitForReadyRead()== true)
{
m_aServerPaket = m_pSocket->readAll();
void CEthernet::DoWork() // run()
{
Lock();
if(m_pSocket->waitForReadyRead()== true)
{
QByteArray m_aServerPaket, m_aServerData ;
m_aServerPaket = m_pSocket->readAll();
To copy to clipboard, switch view to plain text mode
Server side- Dialog class, server class and Thread class
In server class overwritting the incoming connection and sending the socketDescriptor to Dialog class
void EthernetServer::incomingConnection(int socketDescriptor)
{
m_socketDescriptor = socketDescriptor;
SerialProtocolTestWidget m_Widget;
m_Widget.onNewEthernetConnection(socketDescriptor);
}
void EthernetServer::incomingConnection(int socketDescriptor)
{
m_socketDescriptor = socketDescriptor;
SerialProtocolTestWidget m_Widget;
m_Widget.onNewEthernetConnection(socketDescriptor);
}
To copy to clipboard, switch view to plain text mode
In Dialog class
only initalizing the new thread instance. communication should be done only after button press in the dialog.
void SerialProtocolTestWidget::onNewEthernetConnection(int socketDescriptor)
{
m_EthernetThread1 = new EthernetThread(socketDescriptor,this);
}
void SerialProtocolTestWidget::onNewEthernetConnection(int socketDescriptor)
{
m_EthernetThread1 = new EthernetThread(socketDescriptor,this);
}
To copy to clipboard, switch view to plain text mode
Data transfer should only be done after button press in the dialog.
void SerialProtocolTestWidget::on_butProgrammwahlEthernet_clicked()
{
m_EthernetThread1->SetData(eProgramChoice, totalSize, id, pData, len,true);
m_EthernetThread1->start();
}
void SerialProtocolTestWidget::on_butProgrammwahlEthernet_clicked()
{
m_EthernetThread1->SetData(eProgramChoice, totalSize, id, pData, len,true);
m_EthernetThread1->start();
}
To copy to clipboard, switch view to plain text mode
In Thread class
EthernetThread
::EthernetThread(int socketDescriptor,
QObject *parent
): QThread(parent
), socketDescriptor
(socketDescriptor
), m_bRun1
(false) {
{
emit error(tcpSocket.error());
return;
}
}
EthernetThread::~EthernetThread(){}
void EthernetThread::run()
{
int WrittenData = tcpSocket.write((char*)pBuff,len);
}
void EthernetThread::SetData(ECommand command, UINT32 payloadSize, UINT32 id, void *pData, UINT32 &packageLength, bool m_run)
{
//m_bRun1 = m_run;
pBuff = MakeDataPackage(command,payloadSize,id,pData,packageLength);
len = packageLength;
}
EthernetThread::EthernetThread(int socketDescriptor, QObject *parent)
: QThread(parent), socketDescriptor(socketDescriptor), m_bRun1(false)
{
if (!tcpSocket.setSocketDescriptor(socketDescriptor,QAbstractSocket::ConnectedState, QIODevice::WriteOnly))
{
emit error(tcpSocket.error());
return;
}
}
EthernetThread::~EthernetThread(){}
void EthernetThread::run()
{
int WrittenData = tcpSocket.write((char*)pBuff,len);
}
void EthernetThread::SetData(ECommand command, UINT32 payloadSize, UINT32 id, void *pData, UINT32 &packageLength, bool m_run)
{
//m_bRun1 = m_run;
pBuff = MakeDataPackage(command,payloadSize,id,pData,packageLength);
len = packageLength;
}
To copy to clipboard, switch view to plain text mode
Thanks for looking upto this.
Your suggestion will be highly appreciated.
P.S: (reduced info)
Dialog starts the server and it has many buttons which sends respective data on click to the connected client. Both server and client runs in different threads.
Bookmarks