Basically I have an application that creates say 5 multicast sockets on the same interface and within the same application, each socket binds to a different multicast IP address/port. When any one of those sockets sends a message, the other 4 sockets within the application end up reading that message. Is this normal behavior?
This is happening in Ubuntu 11.10 using boost.asio and gcc 4.6.
It's normal in some operating systems ;-) You can turn it off with setsockopt() and the IP_MULTICAST_LOOP option.
Sounds strange to me. If you are using UDP, then you should only receive messages associated with the port number of the UDP socket. Of course, if you using multicast at the IP level, then the port number would not matter.
It is quite true (as per EJP) that loopback will cause programs to receive their own messages if loopback isn't disabled. However, the UDP port numbers still apply. A multicast UDP message sent to port x, should not be received by a socket listening for port y.
Related
i wrote a multithreaded UDP server after the following scheme:
Scheme:
1 Receiver Thread
(Multiple Worker Threads, each has an own Socket, not bindend ,just created Ipv4, UDP,Datagram)
Message gets pushed to 1 worker which then proceed's it and then sends an answere with its own socket.
Problem:
This works perfectly on all my own test programs but for some odd reason it doesnt work with an old software for what i am emulating the server. The software uses async Wsa (overlapped), but i still doesn't get why it doesnt work.
Confusion:
It works if I use the same socket for sending as i used for receiving the data on the serverside. I dont get why, udp is a connectionless protocol so how can it detect a different socket?
Confusion: It works if I use the same socket for sending as i used for
receiving the data on the serverside. I dont get why, udp is a
connectionless protocol so how can it detect a different socket?
If you look in the UDP headers of the packets you are sending you will notice that they contain a "UDP Source Port" field. That field can be examined by the receiver of the packet (via recvfrom()) to find out which UDP port the sending UDP socket used on the sending machine (note that this is different from the "UDP Destination Port" field that determines which port the packet should be delivered to on the receiving machine). It's possible that in your case, the program you are communicating with is looking at that field and adjusting its behavior based on that field's value.
If you're wondering what that field will be set to if you never called bind() on the sending UDP socket, the answer is that the OS will choose an available UDP port number to send from (essentially an implicit bind()).
I have two computers, and I have created a network between them, One is server (Windows Server OS) and the client (Windows 10). Both computer also has connection to internet through wifi. To connect two Systems I am using Ethernet Cable
I like to know if I create a program for client in c++ that send packets using internet socket. Should I also create a listener on server too. And should I use port 80 to send packets and same port on server to listen to arriving packets?
Assuming you decide to use TCP, then:
Should I also create a listener on server too?
If you are using a connection-oriented protocol (such as TCP) then you must have one end listening, because otherwise you have no way to create the TCP connection.
And should I use port 80 to send packets and same port on server to listen to arriving packets?
You should use whatever port number you want, as long as something else isn't using it. The actual number doesn't matter as long as the server and client agree.
Valid port numbers are in the range 1 to 65535.
I'm trying to receive multicast packets from a media server. This is the wireshark capture of an example packet:
(source: memecode.com)
There doesn't seem to be any ports involved, just MAC address for source and destination. Most of the source code examples I've seen bind against a specific port when receiving multicast packets. e.g.
https://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzab6%2Frzab6x2multicast.htm
I would like to be able to receive these packets on both Windows and MaxOSX (C++ apps in both cases, ie Win32 API and Carbon, although the Mac port is more important).
How can I do this?
You just create a UDP socket, bind it to the port, join the multicast group, and call recvfrom().
But the packet you captured doesn't look like a UDP multicast packet. Possibly something between the routers? It doesn't have an IP header let alone a UDP header, which is where the IP and port information is,
I have written a service (C++) that runs on the AIX machine and receives Multicast messages from a remote host (my service joins a predefined Multicast group&port pair).
Lately, I've been asked to handle the Multicast messages received from a different host (on a different Multicast group&port, on the same socket. Though I can insist on the same port.
The issue is, that the messages received from each host must be handled differently.
How do I distinguish between these messages? Is there a possibility to retrieve the sender's Multicast group&port pair from the socket/received messages?
While you can identify the remote host's address (not multi-cast group!) with recvfrom(); it's generally not a good idea to perform different actions for different host with listening same port. It's against the rule of least surprise.
So the short answer is to differentiate remote host address.
If you want to differentiate multi-cast groups on the same port, you have to bind multiple sockets with the multi-cast group address.
The code looks like this:
addr.set(239,0,0,1,8888);
udp.socket();
udp.joinmcast(&addr);
udp.bind(&addr);
I am working on an application that will receive RTP packets from another local service over UDP. Early in the protocol, I receive a message with the IP address from which I'll be receiving these RTP packets, but the port number will be given as 0 (zero) ... I'm to open my UDP socket using an ephemeral port. My response to the given message will contain the actual port I've opened so the sender can know where to direct the packets.
My networking library is an implementation of sockets with boost::asio. Where can I find clear information on how to open such a socket without specifying a non-zero port i.e. use an ephemeral port? Searching the boost docs for "ephemeral" doesn't give me networking results.
Of course, I'm open to seeing an actual example, but finding good documentation would also be just fine.
Thanks.
I would question using ephemeral ports like that, but ... - you can bind your UDP socket to port 0, then use local_endpoint() to retrieve actual port assigned by the OS.