Socket not receiving data after shutdown and creation

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Socket not receiving data after shutdown and creation

1,430件の閲覧回数
Mohsin455
Contributor IV

 

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

 

ラベル(1)
タグ(1)
4 返答(返信)

647件の閲覧回数
Mohsin455
Contributor IV

Hi All,

 

             Can anyone please confirm if the procedure for closing and reopening the socket is correct ?

 

Thanks,

Mohsin455

0 件の賞賛
返信

647件の閲覧回数
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Syed,

Have you tested by adding the FLAG_ABORT_CONNECTION flag?

The value for it is:

 

#define FLAG_ABORT_CONNECTION (0x0010) 

I do it in this code and it works all the time:

while(TRUE)

{

  sock = socket(AF_INET, SOCK_DGRAM, 0);

  if (sock == RTCS_SOCKET_ERROR)

  {

   printf("\nError, socket create failed");

   return;

  }

 

  memset((char *) &local_sin, 0, sizeof(local_sin));

  local_sin.sin_family = AF_INET;

  local_sin.sin_port = SERVER_BROADCAST_PORT;

  local_sin.sin_addr.s_addr = INADDR_ANY;

 

  result = bind(sock, &local_sin, sizeof (sockaddr_in));

  if (result != RTCS_OK)

  {

   printf("\nError, bind() failed with error code %lx", result);

  }

  memset((char *) &remote_sin, 0, sizeof(sockaddr_in));

  remote_sin.sin_family = AF_INET;

  remote_sin.sin_port = SERVER_BROADCAST_PORT;

  remote_sin.sin_addr.s_addr = INADDR_BROADCAST;

 

  ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &MyIP_data);

  //printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(MyIP_data.ip));

  snprintf(myBuffer, 50, "ServerForAndroid %x\n", (uint_32)MyIP_data.ip);

  printf("%s",myBuffer);

  //count = sendto(sock, my_buffer, 11, 0, &remote_sin, sizeof(sockaddr_in));

  count = sendto(sock, myBuffer, sizeof (myBuffer), 0, &remote_sin, sizeof(sockaddr_in));

  if (count == RTCS_ERROR)

  {

   printf("\nsendto() failed with error %lx\n", RTCS_geterror(sock));

  }

  else

  {

   printf("\nSent %ld bytes of data.", count);

  }

  shutdown(sock, FLAG_ABORT_CONNECTION);

  _time_delay(1000);

}

I hope this helps you.

-Garabo

647件の閲覧回数
netra
Contributor IV

Diag accept() failed, error 0x1704

InitDiagSocket: Created the stream socket 536899428

Failed to bind the diag stream socket - 0x1633

diag listen() failed - 0x1704

I am receiving above error after shutting down socket using shutdown() and creating again the socket.


0 件の賞賛
返信

647件の閲覧回数
Luis_Garabo
NXP TechSupport
NXP TechSupport

These are the error you are getting:

TCSERR_SOCK_INVALID (RTCS_ERROR_BASE|0x704)

RTCSERR_TCP_ADDR_IN_USE (RTCS_ERROR_BASE|0x633)

Perhaps you are getting out of resources. Make sure you are giving enough memory to the RTCS. Try this in oyour code before creating the RTCS stack:

 

_RTCSTASK_stacksize = 3000;

I hope this helps.

-Garabo