I know UDP is not a connection oriented protocol but UDP is a requirement on what I have to do.
While I’m sending a bunch of packets from a client application to the server application, is there anyway to know if the server application got closed (eg. the user terminated the process)?
One way is to periodically ping the server (in a different thread from the one sending/receiving the data stream) and wait for a response. If the server doesn’t acknowledge the ping, it may be down (although is not guaranteed, this is UDP after all).
But is there a better/simpler way?
There is no reliable way. The protocols I have implemented that use UDP as the transport use a request/response model. For example, SIP, does it this way (in general, of course):
Say you have 2 peers – A and B. If peer A sends a request to peer B, peer B should always send a response back. If peer A does not receive a response in a certain time, it resends the previous message. Peer A will keep resending the message until it gets a response from peer B OR until a specified expiry time (up to you what this is). If that time has expired, you assume that peer B is down.