更新代码
This commit is contained in:
@@ -3,34 +3,27 @@
|
||||
|
||||
WebServer::WebServer(const QString &serverName, SslMode secureMode, QObject *parent) : QWebSocketServer(serverName, secureMode, parent)
|
||||
{
|
||||
connect(this, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||
connect(this, SIGNAL(newConnection()), this, SLOT(slot_newConnection()));
|
||||
}
|
||||
|
||||
void WebServer::newConnection()
|
||||
void WebServer::slot_newConnection()
|
||||
{
|
||||
QWebSocket *socket = this->nextPendingConnection();
|
||||
WebClient *client = new WebClient(socket, this);
|
||||
connect(client, SIGNAL(clientDisconnected()), this, SLOT(disconnected()));
|
||||
connect(client, SIGNAL(disconnected(QString, int)), this, SLOT(slot_disconnected(QString, int)));
|
||||
connect(client, SIGNAL(error(QString, int, QString)), this, SIGNAL(error(QString, int, QString)));
|
||||
connect(client, SIGNAL(sendData(QString, int, QString)), this, SIGNAL(sendData(QString, int, QString)));
|
||||
connect(client, SIGNAL(receiveData(QString, int, QString)), this, SIGNAL(receiveData(QString, int, QString)));
|
||||
|
||||
QString ip = client->getIP();
|
||||
int port = client->getPort();
|
||||
emit clientConnected(ip, port);
|
||||
emit sendData(ip, port, "客户端上线");
|
||||
|
||||
emit connected(client->getIP(), client->getPort());
|
||||
//连接后加入链表
|
||||
clients.append(client);
|
||||
}
|
||||
|
||||
void WebServer::disconnected()
|
||||
void WebServer::slot_disconnected(const QString &ip, int port)
|
||||
{
|
||||
WebClient *client = (WebClient *)sender();
|
||||
QString ip = client->getIP();
|
||||
int port = client->getPort();
|
||||
emit clientDisconnected(ip, port);
|
||||
emit sendData(ip, port, "客户端下线");
|
||||
|
||||
emit disconnected(ip, port);
|
||||
//断开连接后从链表中移除
|
||||
clients.removeOne(client);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user