I have a server and a client set up using the net
module for Node.js.
Here is my server’s code:
const server = net.createServer(function(socket) {
socket.on("data", function(data) {
// Do stuff with the connection
socket.end();
});
});
server.listen(this.port);
Here is my client’s code:
const client = new net.Socket();
client.connect(this.port, this.host, function() {
client.write("Test Message");
});
When run on the same machine, both of these work fine, but when I try to connect from a different computer, the client hangs at client.connect()
forever (until I terminate the process). When I tried to use the telnet
command in command prompt, I don’t get a response from the server, but the client doesn’t just say connection refused. What’s going on here?