代码拉取完成,页面将自动刷新
同步操作将从 fensnote/qt5-Tcp端口转发服务器 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "ctaskproc.h"
CTaskProc::CTaskProc(int id,QTcpSocket* &client, QString ip, int port, QObject *parent) :
m_id(id),pLocalClient(client),m_ip(ip),m_port(port), QObject(parent)
{
m_valid = true;
connect(pLocalClient, SIGNAL(readyRead()), this , SLOT(recvClientData()));
connect(pLocalClient, SIGNAL(disconnected()), this, SLOT(diconnect()));
pToSvrClient = new QTcpSocket;
connect(pToSvrClient, SIGNAL(readyRead()),this, SLOT(recvSvrData()));
connect(pToSvrClient, SIGNAL(disconnected()),this, SLOT(diconnect()));
connect(pToSvrClient,SIGNAL(error(QAbstractSocket::SocketError)),
this,SLOT(procConnectErr(QAbstractSocket::SocketError)));
connect(pToSvrClient, SIGNAL(connected()), this, SLOT(procConnectOk()));
QHostAddress serverIP;
serverIP.setAddress(m_ip);
pToSvrClient->connectToHost(serverIP, m_port);
}
CTaskProc::~CTaskProc()
{
pToSvrClient->close();
pLocalClient->close();
delete pToSvrClient;
delete pLocalClient;
}
void CTaskProc::stop()
{
m_valid = false;
disconnect(pToSvrClient, SIGNAL(disconnected()),this, SLOT(diconnect()));
disconnect(pLocalClient, SIGNAL(disconnected()), this, SLOT(diconnect()));
pToSvrClient->close();
pLocalClient->close();
}
void CTaskProc::recvClientData()
{
while (pLocalClient->bytesAvailable()>0)
{
QByteArray datagram;
datagram.resize(pLocalClient->bytesAvailable());
pLocalClient->read(datagram.data(), datagram.size());
pToSvrClient->write(datagram);
emit sigReadLocalClientData(m_id,datagram);
}
}
void CTaskProc::recvSvrData()
{
while (pToSvrClient->bytesAvailable()>0)
{
QByteArray datagram;
datagram.resize(pToSvrClient->bytesAvailable());
pToSvrClient->read(datagram.data(), datagram.size());
pLocalClient->write(datagram);
emit sigReadSvrClientData(m_id,datagram);
}
}
void CTaskProc::procConnectErr(QAbstractSocket::SocketError)
{
qDebug()<<"to svr: "<<m_ip<<":"<<m_port<<": "<<pToSvrClient->errorString();
pLocalClient->close();
}
void CTaskProc::procConnectOk()
{
qDebug()<<"OnTaskStartOk: "<<m_id;
emit sigTaskStartOk(m_id);
}
void CTaskProc::diconnect()
{
if(m_valid)
{
m_valid = false;
pToSvrClient->close();
pLocalClient->close();
emit sigTaskEnd(m_id);
}
}
//发给svr的数据
void CTaskProc::sendToServer(QByteArray &data)
{
pToSvrClient->write(data);
}
//发给dev的数据
void CTaskProc::sendToDevice(QByteArray &data)
{
pLocalClient->write(data);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。