Search code examples
node.jstestingnetwork-programmingwebsocketlocalhost

How to disconnect from localhost?


Is it possible to disconnect from localhost?

I'm writing a Node.js WebSocket server, and I want to test locally what would happen if the connection closes erroneously.

If I were testing remotely, I'd just Turn Wi-Fi Off, but that doesn't disconnect my connection to localhost.

Thoughts?


Solution

  • localhost is just an alias in your hosts file. If you remove that alias then you'll be effectively "disconnecting" from localhost.