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


C++ Host::address方法代码示例

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


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

示例1: printHosts

		void printHosts()
		{
			printf("Hosts:\n");
			for (Host::Iterator it = ep.hosts(); it.hasNext(); ) {
				Host h = it.next();
				printf("  %s", h.keyStr().c_str());
				Address addr = h.address();
				if (addr.isValid())
					printf(" - %s", addr.toString().c_str());
				printf("\n");
			}
		}
开发者ID:cusnir,项目名称:gocusp,代码行数:12,代码来源:server.cpp

示例2: makeServerText

QString ServersComboBox::makeServerText(const Host &host)
{
	QString name;
	name = host.address();
	if (host.isValid()) {
		if (name.indexOf(':') >= 0) {
			name = '[' + name + ']';
		}
		name += ':' + QString::number(host.port());
	}
	return name;
}
开发者ID:soramimi,项目名称:SkyMPC,代码行数:12,代码来源:ServersComboBox.cpp

示例3: data

QVariant HostModel::data(const QModelIndex &index, int role) const
{
    if (index.row() < 0 || index.row() >= m_hosts.count())
        return QVariant();

    Host* host = m_hosts.at(index.row());

    switch (index.column()) {
    case 0: {
        switch (role) {
        case NameRole: return host->name();
        case AddressRole: return host->address();
        }
        break;
    }
    case 1: if (role == Qt::DisplayRole) return host->name(); break;
    case 2: if (role == Qt::DisplayRole) return host->productVersion(); break;
    case 3: if (role == Qt::DisplayRole) return host->systemName(); break;
    case 4: if (role == Qt::DisplayRole) return QString("%1:%2").arg(host->address()).arg(host->port()); break;
    }

    return QVariant();
}
开发者ID:hallenberg,项目名称:qmllive,代码行数:23,代码来源:hostmodel.cpp

示例4: send

bool UdpSocket::send(const Host& host, const char* data, int size)
{
    const uint32_t addr = host.address();
    const uint16_t port = htons(host.port());
    sockaddr_in& to = mPriv->to;

    if (to.sin_addr.s_addr != addr || to.sin_port != port) {
        if (to.sin_addr.s_addr)
            close(mPriv->client);
        to.sin_family = AF_INET;
        to.sin_addr.s_addr = addr;
        to.sin_port = port;
        mPriv->client = socket(AF_INET, SOCK_DGRAM, 0);
        if (mPriv->client == INVALID_SOCKET) {
            memset(&to, 0, sizeof(sockaddr_in));

            const int err = socketError();
            fprintf(stderr, "socket failed in send: %d %s\n", err, socketErrorMessage(err).c_str());

            return false;
        }
    }

    int err;
    ssize_t total = 0, sent;
    do {
        sent = sendto(mPriv->client, &data[total], size - total, 0, reinterpret_cast<sockaddr*>(&to), sizeof(sockaddr_in));
        if (sent == SOCKET_ERROR) {
            const int err = socketError();
            if (err == EINTR)
                continue;
            fprintf(stderr, "sendto failed in send: %d %s (addr %u %u)\n", err, socketErrorMessage(err).c_str(), addr, host.port());

            close(mPriv->client);
            memset(&to, 0, sizeof(sockaddr_in));
            return false;
        }
        total += sent;
    } while (total < size);

    assert(total == size);
    return true;
}
开发者ID:jhanssen,项目名称:missouri,代码行数:43,代码来源:UdpSocket.cpp


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