SIGPIPE error in iOS4 when app is running background and lock screen
I use BSD socket in my app to send and receive data on iphone4(iOS4.1),there are three situations in my app:
- app is running in foreground and screen locks, it's fine.
- app is running in background and screen does't lock, it's fine too(I use NSStream to send and receive data for keep app alive in background,it works fine.)
- app is running in background and screen locks, app running fine but always get the SIGPIPE error when app try to call sendto() or send() through UDP or TCP socket.
I search a lot but get nothing useful,from here i know what SIGPIPE is , and i use setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(int)) to avoid app exit abnormally. but i still don't know why this error occurred only in situation 3 and how to send data normally through bsd socket in this situation.
I have try to renew and reconnect but it does't work,it still get SIGPIPE error. I think it maybe that all BSD sockets cannot get internal access in situation 3(As far as we know that BSD socket cannot activate wifi or EDGE connection in iOS),Anyone can help me o开发者_C百科r give me some suggestions? and sorry for my Broken English^.^,Thank you very much .
I search on google and found my own question 10 months before, that's interesting. I already had a solution for application keep running in background , and setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(int)) is useful which will ignore Sigpipe 13 error .
this error happens when the socket already lost physical connection and still try to write data,through Wifi, 3G or Accessory.
精彩评论