/
tcpclientsocket.cpp
66 lines (62 loc) · 1.93 KB
/
tcpclientsocket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "tcpclientsocket.h"
TcpClientSocket::TcpClientSocket(QObject *parent,int port)
{
connect(this,SIGNAL(readyRead()),this,SLOT(dataReceived()));
// connect(this,SIGNAL(sendtoall(QString)),this,SLOT(dataReceived(QString)));
connect(this,SIGNAL(disconnected()),this,SLOT(slotDisconnected()));
isfirst=port;
}
//void TcpClientSocket::dataReceived(QString msg)
//{
//// emit updateClients(msg,msg.length());
//}
void TcpClientSocket::dataReceived(){
QString name=this->readAll();
if(isfirst==6666){
qDebug()<<name;
QStringList tmp=name.split(" ");
if(q.Iscontent(tmp[0],tmp[2].toInt())){
classname=tmp[2].toInt();
if(classname>=3){
return;
}
this->write("yes\n");
this->write(q.getquestioncontent().toUtf8());
this->flush();
this->write(q.avaqueue(classname).toLatin1());
this->flush();
this->write("\nmdzz");
this->flush();
}else{
this->write("no");
}
qDebug()<< "登陆 ";
}else{
qDebug() << "选题内容 " <<name;
QStringList tmp=name.split("|");
classname=tmp[2].toInt();
qDebug() << classname;
qDebug()<< tmp;
if(q.selectquestion(tmp[0],classname,tmp[1].toInt())){
this->write("OK");
emit disconnected(this->socketDescriptor());
}else{
qDebug() << "error\n";
this->write("error");
this->write(q.avaqueue(classname).toLatin1());
this->flush();
}
qDebug()<< "选题 ";
}
}
void TcpClientSocket::slotDisconnected()
{
emit disconnected(this->socketDescriptor());
qDebug()<< "tcpclient类发送信号 " <<this->socketDescriptor() ;
}
//void TcpClientSocket::sendtoal(QString a){
// emit sendtoall(a);
//}
void TcpClientSocket::setwherequestion(QString a){
q.wherequestion(a);
}