本文整理汇总了C++中Endpoint::get_port方法的典型用法代码示例。如果您正苦于以下问题:C++ Endpoint::get_port方法的具体用法?C++ Endpoint::get_port怎么用?C++ Endpoint::get_port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Endpoint
的用法示例。
在下文中一共展示了Endpoint::get_port方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: confEndpoint
bool UDPSocket::confEndpoint(Endpoint & ep)
{
char * host;
char cmd[30];
if (!endpoint_configured) {
host = ep.get_address();
if (host[0] != '\0') {
// set host
sprintf(cmd, "set i h %s\r", host);
if (!wifi->sendCommand(cmd, "AOK"))
return false;
// set remote port
sprintf(cmd, "set i r %d\r", ep.get_port());
if (!wifi->sendCommand(cmd, "AOK"))
return false;
wifi->exit();
endpoint_configured = true;
return true;
}
}
return true;
}
示例2: main
int main() {
bool result = false;
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("UDP client IP Address is %s\n", eth.getIPAddress());
UDPSocket sock;
sock.init();
Endpoint nist;
nist.set_address(HTTP_SERVER_NAME, HTTP_SERVER_PORT);
char out_buffer[] = "plop"; // Does not matter
sock.sendTo(nist, out_buffer, sizeof(out_buffer));
union {
char in_buffer_tab[4];
unsigned int in_buffer_uint;
};
const int n = sock.receiveFrom(nist, in_buffer_tab, sizeof(in_buffer_tab));
if (n > 0) {
result = true;
const unsigned int timeRes = ntohl(in_buffer_uint);
const float years = timeRes / 60.0 / 60.0 / 24.0 / 365;
printf("UDP: Received %d bytes from server %s on port %d\r\n", n, nist.get_address(), nist.get_port());
printf("UDP: %u seconds since 01/01/1900 00:00 GMT ... %s\r\n", timeRes, timeRes > 0 ? "[OK]" : "[FAIL]");
printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years, timeRes > YEARS_TO_PASS ? "[OK]" : "[FAIL]");
if (years < YEARS_TO_PASS) {
result = false;
}
}
sock.close();
eth.disconnect();
notify_completion(result);
return 0;
}