本文整理汇总了C++中NetAddress::port方法的典型用法代码示例。如果您正苦于以下问题:C++ NetAddress::port方法的具体用法?C++ NetAddress::port怎么用?C++ NetAddress::port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetAddress
的用法示例。
在下文中一共展示了NetAddress::port方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addressToPTB
static shared_ptr<PixelTransferBuffer> addressToPTB(const NetAddress& addr) {
std::string str = std::string("HTTP://") + addr.ipString() + ":" + format("%d", addr.port());
debugAssert(str.size() <= 28);
QRcode* qrcode = encode(str.c_str(), (int)str.size());
const int N = qrcode->width;
shared_ptr<PixelTransferBuffer> buffer = CPUPixelTransferBuffer::create(N, N, ImageFormat::L8());
unorm8* dst = reinterpret_cast<unorm8*>(buffer->mapWrite());
const unsigned char* src = qrcode->data;
const unorm8 BLACK = unorm8::fromBits(0x00);
const unorm8 WHITE = unorm8::fromBits(0xFF);
for (int i = 0; i < N * N; ++i) {
// The bytes are in the opposite convention
dst[i] = (src[i] & 1) ? BLACK : WHITE;
}
dst = NULL;
buffer->unmap();
QRcode_free(qrcode);
return buffer;
}
示例2: connect
//-----------------------------------------------------------------------------
bool TCPSocket::connect(const NetAddress& destination)
{
int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sd <= 0)
{
os::printf("Failed to open socket\n");
m_socket = 0;
return false;
}
m_socket = sd;
sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(destination.address());
address.sin_port = htons(destination.port());
if (::connect(sd, (const sockaddr*)&address, sizeof(sockaddr_in)) < 0)
{
os::printf("Failed to connect socket\n");
close();
return false;
}
return true;
}