AnsweredAssumed Answered

Socket not receiving data after shutdown and creation

Question asked by Mohsin455 on Aug 6, 2012
Latest reply on Dec 10, 2012 by Garabo

 

Hi All,

 

           I am using MQX 3.8 and TWRK60N512. I am receiving data from multicast address and it works fine. The issues is once I shutdown a socket and open it again, I am not able to receive any data. Below is the code I  have used for shutting down and reopening the socket. Is there anything else required after shutting down the socket ?

 

 

 /*  ** Send an DROP MEMBERSHIP message via setsockopt  */ errcode = setsockopt(rx_sock, SOL_IGMP, RTCS_SO_IGMP_DROP_MEMBERSHIP, &mc_req, sizeof(mc_req));  if (errcode != RTCS_OK) {  printf("error");  _task_block(); }  /*  ** Shutdown the existing socket  */ errcode = shutdown(rx_sock, 0); if (errcode != RTCS_OK) {  printf("error");     _task_block(); }  /*  ** Create socket to join multicast group on  */ rx_sock = socket(PF_INET, SOCK_DGRAM, 0);  if (rx_sock == RTCS_SOCKET_ERROR) {  printf("error");     _task_block(); }  /*  ** Construct a multicast address structure  */ memset(&rx_addr, 0, sizeof(rx_addr)); rx_addr.sin_family      = AF_INET; rx_addr.sin_addr.s_addr = INADDR_ANY; rx_addr.sin_port        = port;   /*  ** Bind to multicast address to socket  */ errcode = bind(rx_sock, &rx_addr, sizeof(rx_addr)); if (errcode != RTCS_OK) {  printf("error");     _task_block(); }  /*  ** Construct an IGMP join request structure  */ mc_req.imr_multiaddr.s_addr = multicast_address; mc_req.imr_interface.s_addr = ip_address;  /*  ** Send an ADD MEMBERSHIP message via setsockopt  */ errcode = setsockopt(rx_sock, SOL_IGMP, RTCS_SO_IGMP_ADD_MEMBERSHIP, &mc_req, sizeof(mc_req));   if (errcode != RTCS_OK) {  printf("error");     _task_block(); }

 

 

Thanks,

Mohsin455

 

Outcomes