简体   繁体   中英

How to implement client-server udp multicast in one program?

I have written a server and a client both as separate apps. They communicate through UDP Multicast (becouse I need that everyone who joins the group can read & write messages). Now I have two windows, but my aim is to create one simple chat program, but I don't know how to listen and send at the same time. Do I need to create 2 sockets? Or can I use just one? I've even tried to merge both apps in one, but I didn't succeeded (I know, I know.. but I was kinda desperate).

I've searched google for a tut, but didn't succeeded.

I'm using c++.

You can use one or two sockets, it all depends on whether you wish to bind to a particular network adapter and whether you wish to use unicast & broadcast packets. It is often easier to manage one for sending and one for receiving.

To listen to sent multicast packets on the same host check the IP_MULTICAST_LOOP socket option, noting it applies differently on Windows to Unix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM