Thread: IPv6 multicast client fails to receive server response

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    6

    IPv6 multicast client fails to receive server response

    Hi,
    I have written a IPv6 multicast client and server. Client can successfully send packet to server on ff00::1 and server do receive the message. However, when server replies back to client, recvfrom never returns. sento at server does not report any error.

    Any help on identifying the problem will be highly appreciable.
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    6
    BTW, this is a c program and is being tested on windows XP sp2.

    Another interesting observation is that if server and client are running on same machine everything works fine. However, client could not catch response sent by multicast server if running on different machines.
    In case of unicast i can send message to and fro between the same two machines.

    One minor correction to original message - multicast address used is FF02::1 (all node link-local)
    Last edited by perfect; 06-16-2009 at 04:12 AM.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I have written a IPv6 multicast client and server. Client can successfully send packet to server on ff00::1 and server do receive the message. However, when server replies back to client, recvfrom never returns. sento at server does not report any error.

    Hmm...well, my crystal ball is broken right now, so I'm afraid you'll have to be much less vague.

    A working code snippet to demonstrate the problem (or at least a hell of lot more information) might help.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Did the client subscribe to the correct multicast group?

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    6
    Here is the code snippet.
    Code:
    Multicast Client:
    ...
    /* Resolve destination address for multicast datagrams */
       memset(&Hints, 0, sizeof (Hints));
       Hints.ai_family = PF_INET6;
       Hints.ai_socktype = SOCK_DGRAM;
       Hints.ai_protocol = IPPROTO_UDP;
       Hints.ai_flags = AI_NUMERICHOST;
       
       RetVal = getaddrinfo("FF02::1", "7093", &Hints, &multicastAddr);
       if (RetVal != 0) {
          /* error handling */   }
    
       AI = multicastAddr;
       ServSock[i] = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
      
    /* Set TTL limit */  
    multicastTTL = 1; 
      if ( setsockopt(ServSock[i],IPPROTO_IPV6, IPV6_MULTICAST_HOPS ,
    		(char*) &multicastTTL, sizeof(multicastTTL)) != 0 )	{
    		/* Error handling */
    	}
    
            RetVal = sendto(ServSock[i], Buffer, AmountToSend, 0,
    				  (LPSOCKADDR) AI->ai_addr, AI->ai_addrlen);
    	if (RetVal == SOCKET_ERROR) {
    	  /* Error handling */
    	}
         ..... 
    
          AmountRead = recvfrom(ServSock[i], Buffer, sizeof (Buffer), 0,
                                (LPSOCKADDR) &From, &Fromlen);
          if (AmountRead == SOCKET_ERROR) {
             /* Error handling */
          }
    /*********** Here is the issue
    Program never comes out of recvfrom () ***/
    
    
    Server code:
    **********
    /* Resolve the multicast group address - For joining the group */
       memset(&MulticastHints, 0, sizeof(MulticastHints));
       MulticastHints.ai_family = PF_INET6;
       MulticastHints.ai_flags = AI_NUMERICHOST;
    
       RetVal = getaddrinfo("FF02::1", NULL, &MulticastHints, &multicastAddr);
       if (RetVal != 0)    {
         /* Error hanlding */   }
    
    
    /* Get a local address for IPv6 family */
       memset(&LocalHints, 0, sizeof (MulticastHints));
       LocalHints.ai_family = PF_INET6;
       LocalHints.ai_socktype = SOCK_DGRAM;
       LocalHints.ai_protocol = IPPROTO_UDP;
       LocalHints.ai_flags = AI_PASSIVE;   
       
       RetVal = getaddrinfo(NULL, Port, &LocalHints, &localAddr);
       if (RetVal != 0)    {
           /* Error hanlding */ 
       }
    
      AI = localAddr;
    ...
    ServSock[i] = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
    
    bind(ServSock[i], AI->ai_addr, AI->ai_addrlen);
    
    RetVal = join_multicast_group(ServSock[i], &((struct sockaddr_in6*)(multicastAddr->ai_addr))->sin6_addr,
                                        ((struct sockaddr_in6*)(multicastAddr->ai_addr))->sin6_scope_id);		
          if (RetVal != 0)  {
            /* Error handling */
          }
    
    ...
    
    AmountRead = recvfrom(ServSock[i], Buffer, sizeof (Buffer), 0,
    							  (LPSOCKADDR) &From, &FromLen);
    
    ...
    
    RetVal = sendto(ServSock[i], Buffer, AmtSend, 0,
    			   (LPSOCKADDR) &From, FromLen);
    
    ...
    leave_multicast_group(ServSock[i], &((struct sockaddr_in6*)(multicastAddr->ai_addr))->sin6_addr); 
    	   closesocket(ServSock[i]);
    ...

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Now read my last question again. The client needs to join the multicast group to receive multicast messages sent to that group.

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    6
    Thanks for the response.
    If the server response is also sent on multicast address, it will be received by all servers and clients of the group. I want that server response is received by the original sender client only. Thats why i was replying back on the address returned by recvfrom function.
    Am i correct in assuming that server can reply back as a directed call (instead of multicast call)?

    If you think i am still unable to get your point, please share the corrective code snippet, if possible.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Your question doesn't really make any sense.

    ServSock[i] is a socket bound to a multicast address. That means when you send out information on that socket like so:
    Code:
    RetVal = sendto(ServSock[i], Buffer, AmtSend, 0, ...
    Only clients that are part of that multicast group will receive the data. Since your client does not join the multicast group, it will not receive the data.

    Am i correct in assuming that server can reply back as a directed call (instead of multicast call)?
    There is no such thing as a multicast call. All programs can do is send and receive data on sockets. That socket may be a unicast socket, or a multicast socket, but the system calls are the same.

  9. #9
    Registered User
    Join Date
    Jun 2009
    Posts
    6
    Good to see your response again. Thanks for all the help/suggestion you are providing.

    My first question was further to your suggestion that client should also join multicast. Otherwise what is the point of sending response packet on multicast socket. Client will never catch it.

    Anyways, i have figured out that client side firewall setting is the culprit.
    Earlier, i added only Server exe to exception list and was facing issue: client message reaches server, but server response do not.

    Now, i added server exe as well as client exe to exception list on the respective machines and found the two way communication working.

    Strangely, i never required client to be exception in unicast communication. Any idea why the two cases behave differently?

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Any idea why the two cases behave differently?
    As far as a firewall is concerned, the only difference between unicast and multicast is the target IP address.

    Otherwise what is the point of sending response packet on multicast socket. Client will never catch it.
    That's exactly what I was saying. Usually with multicast, if the communication is 2 way, then both sides will join the multicast group. If the client doesn't join the group, then how will the switches and routers between the 2 machines know to route the multicast message back to the client?

    Anyways, looking back at your code I see why it works for you. Your server is sending the response back as a unicast message -- not multicast. That is why your client doesn't need to join the group.

  11. #11
    Registered User
    Join Date
    Jun 2009
    Posts
    6
    As mentioned earlier, code works for me now.

    Thanks for all your support.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  2. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  3. Client works on a LAN but don't send all the data
    By Niara in forum Networking/Device Communication
    Replies: 9
    Last Post: 01-04-2007, 04:44 PM
  4. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  5. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM

Tags for this Thread