void thread1::run(){ QString name="r111"; if (!mw->m_server.listen(name)) { qDebug() << "Not able to start the Server"; } mw->m_server.listen(name); connect(&mw->m_server, SIGNAL(newConnection()), this, SLOT(socket_new_connection())); exec(); }void thread1::socket_new_connection() { QLocalSocket *clientConnection = mw->m_server.nextPendingConnection(); clientConnection->read(buf,2404); //QByteArray in(clientConnection->readAll()); //char *data = in.data(); memcpy(&a,&buf[0],4); memcpy(&b,&buf[4],2400); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater())); emit toMainWidget();}
ProcessingThread::ProcessingThread(){ m_socket = new QLocalSocket(this); m_serverName = "r111"; connect(m_socket, SIGNAL(connected()), this, SLOT(socket_connected())); connect(m_socket, SIGNAL(disconnected()), this, SLOT(socket_disconnected())); connect(m_socket, SIGNAL(readyRead()), this, SLOT(socket_readReady())); connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(socket_error(QLocalSocket::LocalSocketError)));}void ProcessingThread::send_MessageToServer() { m_socket->abort(); m_socket->connectToServer(m_serverName);}void ProcessingThread::socket_connected(){ u_short *from = (u_short*)b ; memcpy(&msg[0],&a,4); memcpy(&msg[4],from,2400); m_socket->write(msg); m_socket->flush();}