This sample demonstrates how to use the State pattern to create a client socket that doesn't break when it loses connection with the server. To install all the dependencies: npm install To try the sample run in two different terminals: node server And then: node client You can try to shutdown (ctrl+c) and restart the server several times to see the state in the client changing from online to offline and then back to online when the server is resurrected.