My iPhone application is using AsyncUdpSocket to handle a UDP socket. However, when my application goes into the background in iOS 4.0 and returns to the foreground, I am getting the following error:
Application 'MyAppName' exited abnormally with signal 13: Broken pipe
This is because my sockets are disconnected when my application goes to the background.
How can I avoid this and run UDP sockets in the background?
Close the socket Since there is no concept of a connection in UDP, there is no need to call shutdown. However, the socket still uses up a file descriptor in the kernel, so we can free that up with the close system call just as we do with files.
UDP socket routines enable simple IP communication using the user datagram protocol (UDP). The User Datagram Protocol (UDP) runs on top of the Internet Protocol (IP) and was developed for applications that do not require reliability, acknowledgment, or flow control features at the transport layer.
Datagram (UDP) sockets. The CONNECT command enables an application to associate a socket with the socket name of a peer. The socket then is considered to be a connected UDP socket. You can call the CONNECT command multiple times with different peer names to change the socket association.
User Datagram Protocol (UDP) UDP is a simple transport-layer protocol. The application writes a message to a UDP socket, which is then encapsulated in a UDP datagram, which is further encapsulated in an IP datagram, which is sent to the destination.
This is not related to UDP. EPIPE
only happens for "stream" file descriptors - Unix pipes and TCP sockets.
I'm guessing you have some sort of a control TCP connection which times out on the remote end when you go into background. You need to figure out how to keep it alive or re-connect when the app wakes up.
You can also handle (or ignore) EPIPE
, see sigaction(2)
, and react to it accordingly on return from write(2)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With