Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run UDP sockets in the background in an iPhone application?

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?

like image 452
S.P. Avatar asked Oct 21 '10 14:10

S.P.


People also ask

Do you need to close UDP sockets?

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.

Can sockets be UDP?

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.

What is a connected UDP socket?

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.

What is UDP socket API?

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.


1 Answers

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).

like image 146
Nikolai Fetissov Avatar answered Oct 28 '22 12:10

Nikolai Fetissov