linux - Socket unable to detect disconnect -


i have written server code accepts connection through client on wifi. wifi socket opened on wifi dongle shows ttyama0.

i create socket

serv_addr.sin_family = af_inet;  serv_addr.sin_addr.s_addr = inaddr_any;  serv_addr.sin_port = htons(port);

then usual accept...

while(1)          {                  new_fd = accept(sfd,(struct sockaddr*)&client_addr,&len);                 ...          ...          }

and in 1 of reader threads doing this:

void* command2buff(void *args)  {   ...          while(1)          {                   ....                  clientbytes = recv(str_fd.new_conn_fd,&temp,1);                  if(clientbytes == 0 || clientbytes == -1)                  {                     ...                  }                  globalcmdbuf[wr] = temp;                           }  }

so recv should detect remote connection has turned off. when turn wifi off android phone code on embedded machine hangs.

i turn on wifi on phone , can connect socket yet there no transfer of data.

  1. i tried read instead of recv didn't make difference.
  2. i have tried tcpalive option well..still doesn't work.
  3. should remove inaddr_any , write wlan....in case should write

serv_addr.sin_addr.s_addr = wlan;

as per ejp' suggestions used so_rcvtimeo turn off connection side.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -