how to implement broadcast function with wxwidgets?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Jade King
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Oct 31, 2005 9:11 am

how to implement broadcast function with wxwidgets?

Post by Jade King » Mon Oct 31, 2005 9:17 am

hello,
in a LAN,i want to braoad some pc with the special port,then how can i implement broadcast function with wxwidgets?

yours jade king

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Nov 02, 2005 8:11 am

Hi!
Just setup a datagram socket, pass the options and listen for incoming communication using the events. Like

Code: Select all

        wxIPV4address addr;
        addr.AnyAddress();
	addr.Service(30301);
	m_multicastSocket = new  wxDatagramSocket(addr,wxSOCKET_REUSEADDR);

	if(m_multicastSocket->Ok())
	{	ip_mreq mreg;
                memset(&mreq,0,sizeof(ip_mreq));
		mreq.imr_multiaddr.s_addr = inet_addr(GROUP_DEFAULT);	/* group addr you want to use*/ 
		mreq.imr_interface.s_addr = htons(INADDR_ANY);
		m_multicastSocket->SetOption(IPPROTO_IP, IP_ADD_MEMBERSHIP, (char far *)&mreq,sizeof(mreq));

		m_multicastSocket->SetNotify(wxSOCKET_INPUT_FLAG);
		m_multicastSocket->Notify(true);
		m_multicastSocket->SetEventHandler(*this, ID_MULTICAST);
	}
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Jade King
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Oct 31, 2005 9:11 am

Post by Jade King » Wed Nov 02, 2005 9:08 am

i will try it

tks


yours
jade king

Post Reply