1 Star 0 Fork 1

wujin0212/WebBrowser

forked from listening2020/WebBrowser 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
HWTcpSocket.cpp 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
#include "HWTcpSocket.h"
#include <QDebug>
#include <QUrl>
HWTcpSocket::HWTcpSocket(QObject *parent) : QObject(parent)
{
mTcpServer = new QTcpServer(this);
mTcpReceiver = new QTcpSocket(this);
auto status = mTcpServer->listen(QHostAddress::LocalHost,13151);
if(status)
{
QObject::connect(mTcpServer,&QTcpServer::newConnection,this,&HWTcpSocket::ReceiveData);
}
}
HWTcpSocket::~HWTcpSocket()
{
mTcpServer->close();
mTcpReceiver->close();
}
void HWTcpSocket::ReceiveData()
{
qCout<<"new connect";
mTcpReceiver = mTcpServer->nextPendingConnection();
// auto ip = mTcpReceiver->peerAddress();
// auto port = mTcpReceiver->peerPort();
// auto iport = QString("connect success ip: %1:%2").arg(ip.toString()).arg(port);
// qDebug() << iport;
connect(mTcpReceiver,&QTcpSocket::readyRead,[=](){
auto ip = mTcpReceiver->peerAddress();
auto port = mTcpReceiver->peerPort();
auto iport = QString("connect success! ip: %1:%2").arg(ip.toString()).arg(port);
qCout << iport;
data = mTcpReceiver->readAll();
qCout<<"received data"<<data;
emit ReceiveSignal();
});
}
QUrl HWTcpSocket::ByteToUrl()
{
if(!data.isEmpty())
return QUrl::fromUserInput(data);
return QUrl();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wujin0212/web-browser.git
git@gitee.com:wujin0212/web-browser.git
wujin0212
web-browser
WebBrowser
master

搜索帮助