基于TCP的網(wǎng)絡(luò)聊天程序

基于TCP的網(wǎng)絡(luò)聊天程序

ID:38796629

大?。?2.44 KB

頁數(shù):5頁

時(shí)間:2019-06-19

基于TCP的網(wǎng)絡(luò)聊天程序_第1頁
基于TCP的網(wǎng)絡(luò)聊天程序_第2頁
基于TCP的網(wǎng)絡(luò)聊天程序_第3頁
基于TCP的網(wǎng)絡(luò)聊天程序_第4頁
基于TCP的網(wǎng)絡(luò)聊天程序_第5頁
資源描述:

《基于TCP的網(wǎng)絡(luò)聊天程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。

1、基于TCP的網(wǎng)絡(luò)聊天程序問題概述:網(wǎng)絡(luò)聊天是網(wǎng)絡(luò)應(yīng)用中的一種常見的功能。TCP是一種可靠的、面向連接、面向數(shù)據(jù)流的傳輸協(xié)議,多數(shù)網(wǎng)絡(luò)協(xié)議都使用TCP協(xié)議,包括HTTP和FTP,TCP協(xié)議非常適合數(shù)據(jù)的連續(xù)傳輸。技術(shù)難點(diǎn):TCP通信協(xié)議;QTcpsocket的使用。實(shí)踐方案:在linux_ubuntu下使用qt_eclipse編寫c++程序。由面向?qū)ο蟮乃枷?,為了?shí)現(xiàn)程序,在server終端部分有3個(gè)類:1.serve2.tcpclient3.tcpserveServe類是繼承自QTcpServer,實(shí)現(xiàn)TCP協(xié)議的服務(wù)器;Tcpclient繼承自QTcpSocket,實(shí)現(xiàn)

2、一個(gè)TCP套接字;Tcpserve是一個(gè)QDialog,負(fù)責(zé)服務(wù)器終端的對(duì)話框顯示與控制。如下是對(duì)serve的實(shí)現(xiàn)代碼:Server.h#include#include"tcpclientsocket.h"classServer:publicQTcpServer{Q_OBJECTpublic:Server(QObject*parent=0,intport=0);QListtcpClientSocketList;signals:voidupdateServer(QString,int);publicslots:voi

3、dupdateClients(QString,int);voidslotDisconnected(int);protected:voidincomingConnection(intsocketDescriptor);};____________________________________________________________________Tcpclient.h#include#includeclassTcpClientSocket:publicQTcpSocket{Q_OBJECTpublic:TcpClientSock

4、et(QObject*parent=0);~TcpClientSocket();signals:voidupdateClients(QString,int);voiddisconnected(int);protectedslots:voiddataReceived();voidslotDisconnected();};__________________________________________________________________Tcpserver.h#include#include#include"server.h"

5、classTcpServer:publicQWidget{Q_OBJECTpublic:TcpServer(QWidget*parent=0,Qt::WindowFlagsf=0);~TcpServer();public:QListWidget*ListWidgetContent;QLabel*LabelPort;QLineEdit*LineEditPort;QPushButton*PushButtonCreate;intport;Server*server;public:voidslotCreateServer();voidupdateServer(QString,in

6、t);};________________________________________________________________Server.cpp#include#include"server.h"Server::Server(QObject*parent,intport):QTcpServer(parent){listen(QHostAddress::Any,port);}voidServer::incomingConnection(intsocketDescriptor){TcpClientSocket*tcpClientSocket

7、=newTcpClientSocket(this);connect(tcpClientSocket,SIGNAL(updateClients(QString,int)),this,SLOT(updateClients(QString,int)));connect(tcpClientSocket,SIGNAL(disconnected(int)),this,SLOT(slotDisconnected(int)));tcpClientSocket->setSocketDescriptor(socketDescriptor);tcp

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無此問題,請(qǐng)放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭(zhēng)議請(qǐng)及時(shí)聯(lián)系客服。
3. 下載前請(qǐng)仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶請(qǐng)聯(lián)系客服處理。