本文整理汇总了C++中QWebSocket::peerName方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebSocket::peerName方法的具体用法?C++ QWebSocket::peerName怎么用?C++ QWebSocket::peerName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebSocket
的用法示例。
在下文中一共展示了QWebSocket::peerName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onNewConnection
void ShtServer::onNewConnection()
{
QWebSocket *socket = socketServer->nextPendingConnection();
connect(socket, &QWebSocket::textMessageReceived, this, &ShtServer::onTextMessage);
connect(socket, &QWebSocket::disconnected, this, &ShtServer::onSocketDisconnected);
//onlineSockets << socket;
qWarning() << "Added socket " << socket->peerName() << ":" << socket->peerPort();
}
示例2: onNewConnection
//! [onNewConnection]
void SslEchoServer::onNewConnection()
{
QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin();
connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString)));
connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray)));
connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
//connect(pSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
m_clients << pSocket;
}
示例3: onNewConnection
//! [onNewConnection]
void SslEchoServer::onNewConnection()
{
QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin();
connect(pSocket, &QWebSocket::textMessageReceived, this, &SslEchoServer::processTextMessage);
connect(pSocket, &QWebSocket::binaryMessageReceived,
this, &SslEchoServer::processBinaryMessage);
connect(pSocket, &QWebSocket::disconnected, this, &SslEchoServer::socketDisconnected);
//connect(pSocket, &QWebSocket::pong, this, &SslEchoServer::processPong);
m_clients << pSocket;
}
示例4: onTextMessage
void ShtServer::onTextMessage(QString msg)
{
QElapsedTimer totalTime;
totalTime.start();
QWebSocket *socket = qobject_cast<QWebSocket *>(sender());
qWarning() << "received: " << msg << "from " << socket->peerName();
//Json
QJsonDocument doc = QJsonDocument::fromJson(msg.toUtf8());
if(!doc.isObject()){
socket->sendTextMessage("json or gtfo");
return;
}
QJsonObject docObj = doc.object();
int r = docObj["request"].toInt();
switch(r){
case 0: //LOGIN
{
QString uuid = docObj["uuid"].toString();
User* u = dbManager->findUserByUuid(uuid);
if(!u){
//DEFAULTS FOR NEW USERS
u = new User();
u->setUuid(QUuid::createUuid().toString());
u->setName("anonimo");
u->setEmail("");
u->setMatches(0);
u->setKilos(0);
u->setState(User::AVAILABLE);
u->setAvatar("263a");
dbManager->addUser(u);
u->setSocket(socket);
}
usersBySocket.insert(socket, u);
QJsonObject obj = u->getJsonObject();
QJsonDocument doc;
doc.setObject(obj);
QByteArray msg = doc.toJson(QJsonDocument::Compact);
socket->sendTextMessage(msg);
}break;
case 1: //GET MATCHES
{
User *u = usersBySocket.value(socket);
if(!u){
qWarning() << "WARNING: getMatches from unknown user";
break;
}
QJsonArray matchesList;
for(Match* m: matches){
QJsonObject matchObj = m->getJsonObject();
matchesList.append(matchObj);
}
QJsonObject obj;
obj["request"] = 1;
obj["matchesList"] = matchesList;
QJsonDocument doc;
doc.setObject(obj);
QByteArray msg = doc.toJson(QJsonDocument::Compact);
socket->sendTextMessage(msg);
}break;
case 2: //CREATE MATCH
{
User* u = usersBySocket.value(socket);
if(!u){
qWarning() << "ERROR: createMatch() user not found";
break;
}
if(u->getPendingMatch() != NULL){
qWarning() << "SKIPPING: user already has a match pending";
break;
}
Match *m = new Match(this);
m->init(u);
m->addPlayer(u);
matches.append(m);
u->setPendingMatch(m);
QJsonObject obj;
obj["request"] = 2;
obj["result"] = "ok";
QJsonDocument doc;
doc.setObject(obj);
QByteArray msg = doc.toJson(QJsonDocument::Compact);
socket->sendTextMessage(msg);
connect(m, &Match::finished, this, &ShtServer::onMatchFinished);
}break;
case 3: //JOIN MATCH
{
User* u = usersBySocket.value(socket);
if(!u){
qWarning() << "ERROR: joinMatch() user not found";
//.........这里部分代码省略.........