I have a a method which listens to events, and everytime an event happens, it should send data to a socket (its udp, so I don't check if the data was received).
what I have in the event_handler is this:
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
socket.sendto(data, (IP, PORT))
It seems to me that I need to create a new socket everytime the event is called, because I don't know how much time will pass between two events, So having a global socket variable and send data on the event doesn't guarantee the socket is still up.
The thing is, because I create the socket everytime, should I dispose/close it after sending the data? what is the best way to dispose or close the socket after use?