0
나는 두 개의 포코 프로그램을 가지고 있는데, 하나는 다른 포코 프로그램을 보낸다. 수신은 충돌하지 않지만 송신을 작동시키지 못합니다. 슬프게도, 예외는별로 도움이되지 않습니다. 그냥 "Net Exception"이라고 말하면됩니다. 동일한 시스템에서 두 프로그램을 모두 실행해야 할 수도 있지만 재사용 주소는 true로 설정되므로 루프백도됩니다.포코 (Poco) 멀티 캐스트 쌍 예제
//Receive
#include <string>
#include <iostream>
// MulticastSocket receive example
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/MulticastSocket.h>
using namespace std;
int main(int argc, char* argv[])
{
Poco::Net::initializeNetwork();
std::cout << "1" << std::endl << std::flush;
//Poco::Net::SocketAddress localAddr(Poco::Net::IPAddress(), 1900);
Poco::Net::SocketAddress localAddr("239.255.255.250", 1900);
std::cout << "2" << std::endl << std::flush;
Poco::Net::MulticastSocket socket(localAddr, true);
std::cout << "3" << std::endl << std::flush;
socket.setLoopback(true);
std::cout << "4" << std::endl << std::flush;
socket.setTimeToLive(4);
std::cout << "5" << std::endl << std::flush;
Poco::Net::SocketAddress groupAddr("239.255.255.250", 1900);
std::cout << "6" << std::endl << std::flush;
socket.joinGroup(groupAddr.host());
std::cout << "7" << std::endl << std::flush;
Poco::Net::SocketAddress sender;
char buffer[512];
int n = socket.receiveFrom(buffer, sizeof(buffer), sender);
std::cout << buffer << std::endl << std::flush;
Poco::Net::uninitializeNetwork();
return 0;
}
//Send
#include <string>
#include <iostream>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/MulticastSocket.h>
#include <Poco/Net/NetException.h>
using namespace std;
using namespace Poco;
int main(int argc, char* argv[])
{
Poco::Net::initializeNetwork();
try
{
Poco::Net::SocketAddress address("239.255.255.250", 1900);
//Poco::Net::SocketAddress address(Poco::Net::IPAddress(), 1900);
std::cout << "1" << std::endl << std::flush;
Poco::Net::MulticastSocket socket(address, true);
std::cout << "2" << std::endl << std::flush;
socket.setLoopback(true);
std::cout << "3" << std::endl << std::flush;
//Poco::Net::SocketAddress sender;
char buffer[512];
buffer[0] = 'H';
buffer[1] = '\0';
std::cout << "Sending " << buffer << std::endl;
//socket.sendTo(buffer, 512, sender);
socket.sendBytes(buffer, 512, 0);
std::cout << "4" << std::endl << std::flush;
}
catch(const Poco::Net::NetException& ex)
{
std::cout << ex.what() << std::endl << std::flush;
}
Poco::Net::uninitializeNetwork();
return 0;
}
[IDF의 @ localhost를 디버그] $에서 netstat -rn 커널 IP 라우팅 테이블 대상 게이트웨이 Genmask 플래그 MSS 창 irtt는 Iface는 192.168.31.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0를 239.0.0.0 0.0.0.0 255.0 .0.0 U 0 0 0 eth0 0.0.0.0 192.168.31.2 0.0.0.0 UG 0 0 0 eth0 [idf @ localhost 디버그] $ ls – Ivan