Keeping server socket live


i have a tcp server socket which listens 3000 port and waits for clients to connect. For some reason, clients cant connect to this server socket after a time. i suspect that the server socket gets down and stops listening. But i dont know how to trigger an event when it gets down.

What i want is to keep the server socket live. if it closed, then i want to restart it. how can i do that?