POCO中UDP方式的Socket,主要有两种:Poco::Net::DatagramSocket、Poco::Net::MulticastSocket。
1 UDPEchoServer echoServer; 2 DatagramSocket ss; 3 ss.connect(SocketAddress("localhost", echoServer.port()));//连接 4 int n = ss.sendBytes("hello", 5);//发送 5 char buffer[256]; 6 n = ss.receiveBytes(buffer, sizeof(buffer));//udp client接收 7 cout<<"n = "<<n<<endl;
1 MulticastEchoServer echoServer; 2 MulticastSocket ms; 3 int n = ms.sendTo("hello", 5, echoServer.group()); 4 char buffer[256]; 5 n = ms.receiveBytes(buffer, sizeof(buffer)); 6 cout<<"n = "<<n<<endl; 7 ms.close();