Created a function for stopping the thread from the client.