本文整理汇总了C++中QAbstractSocket::localAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractSocket::localAddress方法的具体用法?C++ QAbstractSocket::localAddress怎么用?C++ QAbstractSocket::localAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractSocket
的用法示例。
在下文中一共展示了QAbstractSocket::localAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool SignalProxy::IODevicePeer::isSecure() const {
#ifdef HAVE_SSL
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_device);
if(sslSocket)
return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6;
#endif
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
if(socket)
return socket->localAddress() == QHostAddress::LocalHost || socket->localAddress() == QHostAddress::LocalHostIPv6;
return false;
}
示例2: AddNewClient
void SharedDaemon::AddNewClient(const std::string &host, const stringVector &args, void *cbdata)
{
/// Send appropriate message for TCP or WebConnection
void** data = (void**)cbdata;
ConnectionType typeOfConnection = *((ConnectionType*)(data[0]));
QAbstractSocket* socket = static_cast<QAbstractSocket*>(data[1]);
ViewerState* viewerState = static_cast<ViewerState*>(data[2]);
JSONNode node;
QString hostname = typeOfConnection == TcpConnection ? socket->localAddress().toString():
dynamic_cast<QWsSocket*>(socket)->internalSocket()->localAddress().toString();
if(hostMap.contains(hostname)) hostname = hostMap[hostname];
node["host"] = hostname.toStdString(); //host
node["port"] = args[7]; //port
node["version"] = args[2]; //version
node["securityKey"] = args[9]; //key
node["numStates"] = viewerState->GetNumStateObjects(); //number of states
JSONNode::JSONArray rpc_array = JSONNode::JSONArray();
for(size_t i = 0; i < ViewerRPC::MaxRPC; ++i) {
rpc_array.push_back(ViewerRPC::ViewerRPCType_ToString((ViewerRPC::ViewerRPCType)i));
}
node["rpc_array"] = rpc_array;
if(typeOfConnection == TcpConnection)
{
QTcpSocket *tsocket = dynamic_cast<QTcpSocket*>(socket);
std::string message = node.ToString();
tsocket->write(message.c_str(),message.length());
if(tsocket->state() != QAbstractSocket::UnconnectedState)
tsocket->waitForBytesWritten();
tsocket->disconnectFromHost();
if(tsocket->state() != QAbstractSocket::UnconnectedState)
tsocket->waitForDisconnected();
//HKTODO: Do not delete connection (test fix for ORNL machines)
//tsocket->deleteLater();
}
else
{
QWsSocket *wsocket = dynamic_cast<QWsSocket*>(socket);
wsocket->write(QString(node.ToString().c_str()));
wsocket->flush();
if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
wsocket->internalSocket()->waitForBytesWritten();
wsocket->close("");
wsocket->internalSocket()->disconnectFromHost();
if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
wsocket->internalSocket()->waitForDisconnected();
wsocket->deleteLater();
}
}