当前位置: 首页>>代码示例>>C++>>正文


C++ QWebSocket::peerAddress方法代码示例

本文整理汇总了C++中QWebSocket::peerAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebSocket::peerAddress方法的具体用法?C++ QWebSocket::peerAddress怎么用?C++ QWebSocket::peerAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QWebSocket的用法示例。


在下文中一共展示了QWebSocket::peerAddress方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onNewConnection

void WebSocketServer::onNewConnection()
{
    QWebSocket *socket = m_pWebSocketServer->nextPendingConnection();
    JsonApi *api = new JsonApi(socket, socket->peerAddress() == QHostAddress::LocalHost);
    connect(socket, &QWebSocket::disconnected, this, &WebSocketServer::socketDisconnected);
    connect(socket, &QWebSocket::textMessageReceived, api, &JsonApi::processMessage);
    m_clients[socket] = api;
}
开发者ID:enna-project,项目名称:Enna-Media-Server,代码行数:8,代码来源:WebSocketServer.cpp

示例2: onNewConnection

void ReverseHashDServer::onNewConnection(){

    QWebSocket *pSocket = m_pReverseHashDServer->nextPendingConnection();
    std::cout << "NewConnection " << pSocket->peerAddress().toString().toStdString() << " " << pSocket->peerPort() << "\n";
        
    connect(pSocket, &QWebSocket::textMessageReceived, this, &ReverseHashDServer::processTextMessage);
    connect(pSocket, &QWebSocket::binaryMessageReceived, this, &ReverseHashDServer::processBinaryMessage);
    connect(pSocket, &QWebSocket::disconnected, this, &ReverseHashDServer::socketDisconnected);

    m_clients << pSocket;
}
开发者ID:sea-kg,项目名称:reversehash,代码行数:11,代码来源:reversehashd_server.cpp

示例3: onNewConnection

void IqWampRouterPrivate::onNewConnection()
{
    while (m_server->hasPendingConnections()) {
        QWebSocket *socket = m_server->nextPendingConnection();
#ifdef IQWAMP_DEBUG_MODE
        qDebug() << "New connection from " << socket->peerAddress().toString();
#endif
        IqWampCallee *client = new IqWampCallee(socket, this);
        connect(client, &IqWampCallee::hello, this, &IqWampRouterPrivate::onClientHello);

        m_clients << client;
    }
}
开发者ID:ItQuasarOrg,项目名称:IqWamp,代码行数:13,代码来源:iqwamprouter_p.cpp

示例4: onSocketDisconnected

void CardReader::onSocketDisconnected()
{
	QWebSocket *webSocket = qobject_cast<QWebSocket *>(sender());
	if (webSocket) {
		clients.removeAll(webSocket);
		frontend_message(
			QStringLiteral("Client disconnected from %1:%2, now %3 connected client(s) [reason: %4]")
				.arg(webSocket->peerAddress().toString())
				.arg(webSocket->peerPort())
				.arg(clients.length())
				.arg(webSocket->closeCode())
		);
		webSocket->deleteLater();
	}
}
开发者ID:SVArago,项目名称:Arago-Card-Reader,代码行数:15,代码来源:cardreader.cpp

示例5: NewSocketConnection

//=======================
//       PRIVATE SLOTS
//=======================
//GENERIC SERVER SIGNALS
// New Connection Signals
void WebServer::NewSocketConnection(){
  WebSocket *sock = 0;
  if(WSServer!=0){
    if(WSServer->hasPendingConnections()){ 
      QWebSocket *ws = WSServer->nextPendingConnection();
      if( !allowConnection(ws->peerAddress()) ){ ws->close(); }
      else{ sock = new WebSocket( ws, generateID(), AUTH); }
    }
  }else if(TCPServer!=0){
    if(TCPServer->hasPendingConnections()){ 
	QSslSocket *ss = TCPServer->nextPendingConnection();
	if( !allowConnection(ss->peerAddress()) ){ ss->close(); }    
	else{ sock = new WebSocket( ss, generateID(), AUTH); }
    }
  }
  if(sock==0){ return; } //no new connection
  //qDebug() << "New Socket Connection";	
  connect(sock, SIGNAL(SocketClosed(QString)), this, SLOT(SocketClosed(QString)) );
  connect(EVENTS, SIGNAL(NewEvent(EventWatcher::EVENT_TYPE, QJsonValue)), sock, SLOT(EventUpdate(EventWatcher::EVENT_TYPE, QJsonValue)) );
  OpenSockets << sock;
}
开发者ID:lexqbit,项目名称:sysadm,代码行数:26,代码来源:WebServer.cpp

示例6: onNewConnection

void CardReader::onNewConnection()
{
	QWebSocket *webSocket = server->nextPendingConnection();

	connect(webSocket, &QWebSocket::disconnected, this, &CardReader::onSocketDisconnected);
	connect(webSocket, static_cast<void(QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), this, &CardReader::onSocketError);
	connect(webSocket, &QWebSocket::sslErrors, this, &CardReader::onSslError);
	clients.append(webSocket);
	frontend_message(QStringLiteral("Client connected from %1:%2, now %3 connected client(s)").arg(webSocket->peerAddress().toString()).arg(webSocket->peerPort()).arg(clients.length()));
}
开发者ID:SVArago,项目名称:Arago-Card-Reader,代码行数:10,代码来源:cardreader.cpp

示例7: processTextMessage

void WsServer::processTextMessage(QString message)
{
    QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
    if (!pClient) {
        return;
    }
    qDebug()<<message;
	QString senderIP = pClient->peerAddress().toString();
	QStringList messageParts = message.split(",");


	if (messageParts[0]=="play") { // comes in as "play,water|stones|sticks|wind|flute,<pan>"
		QString type = messageParts[1];
		double pan = messageParts[2].toDouble();
		QString scoreLine;
		if (type=="flute") {
			if (onlyOneEventAllowed) {
				if (!fluteIPs.contains(senderIP)) {
					fluteIPs.append(senderIP);
					pClient->sendTextMessage("set flute disable");
					emit eventCountChanged(FLUTE, ++eventCounter[FLUTE]); // increase the counter and send signal to UI
				} else {
					qDebug()<<"Second try from: " << senderIP;
					return;
				}
			}
			scoreLine.sprintf("i \"flute\" 0 15 %f ", pan);
		} else {
			if (onlyOneEventAllowed) {
				if (type=="water" && !waterIPs.contains(senderIP)) {
					waterIPs.append(senderIP);
					emit eventCountChanged(WATER, ++eventCounter[WATER]);
					pClient->sendTextMessage("set water disable");
				} else if (type=="stones" && !stoneIPs.contains(senderIP)) {
					stoneIPs.append(senderIP);
					emit eventCountChanged(STONES, ++eventCounter[STONES]);
					pClient->sendTextMessage("set stones disable");
				} else if (type=="sticks" && !stickIPs.contains(senderIP)) {
					stickIPs.append(senderIP);
					emit eventCountChanged(STICKS, ++eventCounter[STICKS]);
					pClient->sendTextMessage("set sticks disable");
				} else if (type=="wind" && !windIPs.contains(senderIP)) {
					windIPs.append(senderIP);
					emit eventCountChanged(WIND, ++eventCounter[WIND]);
					pClient->sendTextMessage("set wind disable");
				} else {
					qDebug()<<"Seems like second try from: " << senderIP;
					return;
				}
			}
			// get filename as random from the subfolder according to the sound type
			QString path = "../sounds/"+type + "/";
			QDir directory(path);
			QStringList files = directory.entryList(QStringList()<<"*.wav");
			QString filename = path + files[qrand()%files.count()];
			//qDebug()<<"File selected: "<<filename;


			scoreLine.sprintf("i \"play\" 0 5 \"%s\" %f ",filename.toLocal8Bit().data(), pan);
		}
		qDebug()<< scoreLine;
		emit newEvent(scoreLine);
	}


}
开发者ID:tarmoj,项目名称:waiting-game,代码行数:66,代码来源:wsserver.cpp


注:本文中的QWebSocket::peerAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。