title: c#: How to safely send multicast packets without interference?
body: <p>Sorry if the title is hard to understand but I don't really know how to put it in short. Let me explain.</p>
  
  <p>I am currently developing a LAN-filesharing university project.
  Everyone running the application will have to notify others that they available for file transfer. My idea is to Join a multicast group upon launch, and send a sort of "keep alive" packet in multicast: with keep alive I mean that this packet will tell all the receivers that the sender is still available for transferring files, if other users want to. So e.g.: I'm running the app and it will send this packet every 50 s or so, and other people in my network running my application will receive this packet and keep me in their memory.</p>
  
  <p>This is what the client does (this is just an example, not actual code), at this point of the app I have already joined the multicast group and set the destination end point:</p>
  
  <pre><code>//   Sending first data, e.g.: my ip address...
  client.Send(buffer, buffer.Length, MulticastAddressEndPoint);
  
  //   Sending other data, e.g.: my real name...
  client.Send(buffer2, buffer2.Length, MulticastAddressEndPoint);
  
  //   Sending other data, e.g.: my username...
  client.Send(buffer3, buffer3.Length, MulticastAddressEndPoint);
  </code></pre>
  
  <p>From the official documentation I read that Send:</p>
  
  <blockquote>
    <p>Sends a UDP datagram to the host at the specified remote endpoint.</p>
  </blockquote>
  
  <p>So I'm guessing that <em>I am</em> sending <strong>3</strong> datagrams. </p>
  
  <p>My listener thread is something like this:</p>
  
  <pre><code>IPEndPoint from = new IPEndPoint(IPAddress.IPv6Any, port);
  
  while(true)
  {
      //  Receive the ip
      byte[] data = client.Receive(ref from);
  
      //  Receive the first name
      data = client.Receive(ref from);    
  
      //  Receive the username
      data = client.Receive(ref from);    
  }
  </code></pre>
  
  <p>Now for the real question:
  Let's suppose that two people are sending these 3 packets at the exactly same time (with their values of course, so different ip address etc), and no packet is dropped and they are delivered all in the correct sequence (first ip, then name, then username). The question is: I have absolutely <strong><em>NO</em></strong> guarantees that I will receive packets in this order: </p>
  
  <blockquote>
    <p>packet1_A | packet2_A | packet3_A | packet1_B | packet2_B | packet3_B </p>
  </blockquote>
  
  <p>instead of this </p>
  
  <blockquote>
    <p>packet1_A | packet1_B | packet2_A | packet2_B | packet3_A | packet3_B  </p>
  </blockquote>
  
  <p>am I right?
  The only thing that I can do is pack all information in one single byte array and then send it, right? This seems the most reasonable thing to do, but what if my information exceeds the 1500 bytes of ethernet? My datagram will be sent in more packets, so would I experience the same "interference" or my NIC will detect packets belonging to the same datagram and join them again and then deliver it to the OS?</p>