本文整理汇总了C++中UdpSocket::close方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::close方法的具体用法?C++ UdpSocket::close怎么用?C++ UdpSocket::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpSocket
的用法示例。
在下文中一共展示了UdpSocket::close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
UdpSocket client;
client.bind(8002);
const char* message = "ahoj\n";
//client.write("224.3.29.71", 8001, message); multicast
/*int broadcastEnable=1;
int ret = setsockopt(client.get_handle(), SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
client.write("255.255.255.255", 8001, message); // broadcast
*/
printf("Sending to server: %s", message);
client.write("localhost", 8001, message);
sockaddr_in from_addr;
unsigned int from_len;
char buf[1024];
int size = client.readline(buf, sizeof(buf), (sockaddr*) &from_addr);
buf[size] = '\0';
printf("Received from server: %s", buf);
client.close();
return 0;
}
示例2: main
int main()
{
UdpSocket s;
Host h("localhost", 2001);
if (s.sendString("hello world", h) == AbstractSocket::Done)
cout << "Done" << endl;
else
perror("Error");
if (s.sendInt32(666, h) == AbstractSocket::Done)
cout << "Done" << endl;
else
perror("Error");
if (s.sendInt8('&', h) == AbstractSocket::Done)
cout << "Done" << endl;
else
perror("Error");
size_t ts = 21;
if (s.sendCharArray("this is a char array", ts, h) == AbstractSocket::Done)
cout << "Done" << endl;
else
perror("Error");
Frame f;
f << "This is a frame " << 666 << '\n';
if (s.sendFrame(f, h) != AbstractSocket::Done)
perror("error");
else
cout << "done" << endl;
s.close();
}
示例3: main
int main(int argc, char* argv[])
{
/* Concept:
1) UdpSocket listens for input data.
2) Data is passed to H264Decoder which than parses
the NALU files and passes everything to ffmpeg.
The decoded data is than passed to the SdlViewer instance;
3) The SdlViewer uses SDL with OpenGL acceleration to show the received frames.
*/
for(int i = 1; i < argc; ++i) {
std::string value(argv[i]);
if (value == "--fullscreen") {
fullscreen = true;
}else if(value == "--oculus"){
viewer = new OculusViewer(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}else if (value == "--help" || value == "-h") {
cout << "--help no idea what exactly this parameter does" << endl
<< "--fullscreen open fullscreen opengl context instead of vga window" << endl
<< "--oculus adjust screen window for Oculus Rift DK2" << endl;
return 0;
}
}
if(viewer == nullptr){
viewer = new SdlViewer(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
input.initClient(cfg.getValueOfKey<string>("TARGET_IP").c_str(), TARGET_PORT);
input.setInitCallback(&init);
input.send(PROTOCOL_TYPE_INIT, nullptr, 0);
viewer->setInputCallback(&inputCallback);
viewer->setPositionCallback(&positionCallback);
viewer->show(fullscreen);
input.send(PROTOCOL_TYPE_CLOSE, nullptr, 0);
input.close();
return 0;
}