Home/Support/Support Forum/can not receive multicast packet with Connectme9210
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

can not receive multicast packet with Connectme9210

0 votes
Hi,

My application use UDP multicast, and it work fine with Connectme device.

When I apply same code over Connectme9210 device, it can send multicast packet, but do not receive multicast packet.

What issue cause this, and how to do with this problem?

Thanks for any help.

Jiaxin
asked Apr 3, 2018 in NET+OS by jiaxins New to the Community (3 points)

Please log in or register to answer this question.

1 Answer

0 votes
Both ME and ME9210 use the same TCP/iP stack so it should work the same.
answered Apr 3, 2018 by LeonidM Veteran of the Digi Community (2,821 points)
Thanks for your answer.

But they use different BSP, maybe there is different setting cause this problem.
very similar ethernet driver, so it shouldn't really matter.
void multicast_test1(unsigned long thread_input)
{
    struct ip_mreq    stMreq;
    int            s;
    int            result;
    int            i;
    int            size, len;
    int            buffsize = BUFSIZE;
    int            one;
    char        iTmp;

    struct ip_mreq mreq;        // Used in adding or dropping // multicasting addresses
    struct sockaddr_in local_sin,    // Local socket's address
    dest_sin, recv_sin,            // Holds the source address upon
    stFrom;                // recvfrom function returns

    one = 1;

    printf("----  OPEN  ----\n");

    /* get a datagram socket */
    s = socket(AF_INET,SOCK_DGRAM,0);
    if (s == -1)
    {
    error("SOCKET creation error");
    }
    /*
        Bind a receive port to the socket
    */
    memset(&local_sin, 0, sizeof(local_sin));
    local_sin.sin_family = AF_INET;
    local_sin.sin_port = htons(10000);
    local_sin.sin_addr.s_addr = htonl(INADDR_ANY);
 
    result = bind (s, &local_sin, sizeof (local_sin));
    if (result == -1)
    {
    error("BIND error");
    }
    
#if 1
    one = 1;
    result = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&one, sizeof one);
    if (result == -1)
    {
    error("SETSOCKOPT error");
    }
#endif   

    result = setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&buffsize, sizeof(buffsize));
    if (result == -1)
    {
    error("SETSOCKOPT error");
    }

    result = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&buffsize, sizeof(buffsize));
    if (result == -1)
    {
    error("SETSOCKOPT error");
    }

    printf("----  JOIN  ----\n");

    /* join the first multicast group. 224.1.2.4 */
    mreq.imr_multiaddr.s_addr = NAInet_addr("224.1.2.4");
    mreq.imr_interface.s_addr = INADDR_ANY;

    result = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq));
    if (result != 0)
    {
    error("setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq))");
    }

    printf("----  TTL  ----\n");
    /* set TTL to traverse up to multiple routers */
    iTmp = 1;
    result = setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&iTmp, sizeof(iTmp));
    if (result != 0)
    {
    error("setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&iTmp, sizeof(iTmp))");
    }

    printf("----  LOOPBACK  ----\n");
    /* disable loopback */
    iTmp = 0;
    result = setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&iTmp, sizeof(iTmp));
    if (result != 0)
    {
    error("setsockopt(s, SOL_SOCKET, IP_MULTICAST_LOOP, (char *)&iTmp, sizeof(iTmp))");
    }

    /* receiving message */
    for (i = 0; i < 0xffffffff; i++)
    {
    len = sizeof(stFrom);
    result = recvfrom(s, achIn, BUFSIZE, 0, (struct sockaddr_in*)&stFrom, &len);
    printf("%d: multicast_test1 receive data length %d from 0x%X\n", i+1, result, (unsigned)stFrom.sin_addr.s_addr);

    if (result == -1)
    {
        error("recvfrom()");
    }
    }

    printf("\n");

    printf("----  DELETE  ----\n");
    /* delete the multicast group. */
    mreq.imr_multiaddr.s_addr = NAInet_addr("224.1.2.4");

    result = setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&mreq, sizeof(mreq));
    if (result != 0)
    {
    error("setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&mreq, sizeof(mreq))");
    }

    printf("----  TTL  ----\n");

    /* set TTL to traverse up to multiple routers */
    iTmp = 1;
    result = setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&iTmp, sizeof(iTmp));
    if (result != 0)
    {
    error("setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&iTmp, sizeof(iTmp))");
    }
    printf("----  LOOPBACK  ----\n");

    /* disable loopback */
    iTmp = 0;
    result = setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&iTmp, sizeof(iTmp));
    if (result != 0)
    {
    error("setsockopt(s, SOL_SOCKET, IP_MULTICAST_LOOP, (char *)&iTmp, sizeof(iTmp))");
    }

    socketclose(s);

    printf("----  FIN  ----\n");
    {
    }
}
Thank LeonidM

I will try with your sample code.

Thanks again.

Jiaxin
did this work? Are you using wired or wireless module?
...