close socket on window close