资源简介
DT qt项目代码,基于tcp实现

代码片段和文件信息
#include “ClientDemo.h“
#include
#include
#include
ClientDemo::ClientDemo(Qobject* parent) : Qobject(parent) m_handler(NULL)
{
connect(&m_client SIGNAL(connected()) this SLOT(onConnected()));
connect(&m_client SIGNAL(disconnected()) this SLOT(onDisconnected()));
connect(&m_client SIGNAL(readyRead()) this SLOT(onDataReady()));
connect(&m_client SIGNAL(bytesWritten(qint64)) this SLOT(onBytesWritten(qint64)));
}
void ClientDemo::onConnected()
{
if( m_handler != NULL )
{
TextMessage conn(“CONN“ m_client.peerAddress().toString() + “:“ + QString::number(m_client.peerPort()));
m_handler->handle(m_client conn);
}
}
void ClientDemo::onDisconnected()
{
m_assembler.reset();
if( m_handler != NULL )
{
TextMessage dscn(“DSCN“ ““);
m_handler->handle(m_client dscn);
}
}
void ClientDemo::onDataReady()
{
char buf[256] = {0};
int len = 0;
while( (len = m_client.read(buf sizeof(buf))) > 0 )
{
QSharedPointer ptm;
m_assembler.prepare(buf len);
while( (ptm = m_assembler.assemble()) != NULL )
{
if( m_handler != NULL )
{
m_handler->handle(m_client *ptm);
}
}
}
}
void ClientDemo::onBytesWritten(qint64 bytes)
{
(void)bytes;
}
bool ClientDemo::connectTo(QString ip int port)
{
m_client.connectToHost(ip port);
return m_client.waitForConnected();
}
qint64 ClientDemo::send(TextMessage& message)
{
QByteArray ba = message.serialize();
return m_client.write(ba.data() ba.length());
}
qint64 ClientDemo::available()
{
return m_client.bytesAvailable();
}
void ClientDemo::close()
{
m_client.close();
}
bool ClientDemo::isValid()
{
return m_client.isValid();
}
void ClientDemo::setHandler(TxtMsgHandler* handler)
{
m_handler = handler;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1247 2019-06-25 15:22 ChatRoom\ChatRoom.pro
文件 23825 2019-12-25 14:32 ChatRoom\ChatRoom.pro.user
文件 2037 2019-12-25 14:27 ChatRoom\ClientDemo.cpp
文件 732 2019-07-12 17:46 ChatRoom\ClientDemo.h
文件 177 2019-06-24 11:05 ChatRoom\main.cpp
文件 1385 2019-07-12 18:58 ChatRoom\MainWin.h
文件 2157 2019-07-12 19:00 ChatRoom\MainWinSlot.cpp
文件 1934 2019-07-12 19:05 ChatRoom\MainWinUI.cpp
文件 3724 2019-06-24 11:57 ChatRoom\QLoginDialog.cpp
文件 923 2019-06-24 11:57 ChatRoom\QLoginDialog.h
文件 1288 2019-06-11 11:53 ChatRoom\TextMessage.cpp
文件 460 2019-06-11 11:53 ChatRoom\TextMessage.h
文件 2022 2019-06-11 11:58 ChatRoom\TxtMsgAssembler.cpp
文件 669 2019-06-11 11:58 ChatRoom\TxtMsgAssembler.h
文件 226 2019-06-11 14:00 ChatRoom\TxtMsgHandler.h
文件 956 2019-06-25 16:15 ChatRoomServer\ChatRoomServer.pro
文件 23873 2019-12-25 14:32 ChatRoomServer\ChatRoomServer.pro.user
文件 298 2019-06-25 16:18 ChatRoomServer\main.cpp
文件 2979 2019-12-25 14:28 ChatRoomServer\ServerDemo.cpp
文件 709 2019-06-11 14:49 ChatRoomServer\ServerDemo.h
文件 2314 2019-07-12 18:56 ChatRoomServer\ServerHandler.cpp
文件 885 2019-07-12 18:51 ChatRoomServer\ServerHandler.h
文件 1288 2019-06-11 11:53 ChatRoomServer\TextMessage.cpp
文件 460 2019-06-11 11:53 ChatRoomServer\TextMessage.h
文件 2022 2019-06-11 11:58 ChatRoomServer\TxtMsgAssembler.cpp
文件 669 2019-06-11 11:58 ChatRoomServer\TxtMsgAssembler.h
文件 226 2019-06-11 14:00 ChatRoomServer\TxtMsgHandler.h
目录 0 2019-12-25 14:32 ChatRoom
目录 0 2019-12-25 14:32 ChatRoomServer
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:DT数据结构代码 DTlib.rar
- 下一篇:Face-tracking.zip
相关资源
- Omron ETN21模块进行modbustcp通讯
- oracle数据迁移项目实施方案
- CCS中如何生成LIB文件-并在另外CCS项目
- 农场开发项目
- 完整的项目案例
- 组态王中S7-300TCP驱动
- GIS项目开发文档(分析、设计、实现
- ARM嵌入式项目实战
- 基于Apache Mina实现的TCP长连接和短连接
- 项目周报格式(excel格式报表)
- CVI下的TCP服务器和客户端
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- 软件项目技术开发(委托)合同
- TCP 发包工具(windows)
- 软件工程文档模板1可行性研究报告
- CListCtrlExDemo.rar
- 软件项目管理案例教程4
- 软件开发过程文档(开发大纲 编写规
- VxWorks TCPIP协议栈
- socket小工具(可方便建立TCP UDP的soc
- vc 编写的基于TCP协议的客户/服务器
- B2C商城综合系统项目源码
- oracle ebs 11i总帐、应收、应付、库存、
- 基于CSocket的多人聊天室
- 采用WINSOCK2 编写的TCP/UDP通信程序
- DSP 语音识别程序 DTW MFCC
- Modbus TCP Client
- STM8S SX1278 项目和源代码
- 基于改进BSC的电信投资项目后评估体
- 软件系统项目实施方案(通用模板)
评论
共有 条评论