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.
- i tried read instead of recv didn't make difference.
- i have tried tcpalive option well..still doesn't work.
- 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
Post a Comment