I have a very simple WebSocket Server built with Node.js and the WS package.
var WebSocketServer = require('ws').Server
var wss = new WebSocketServer({
port: 8080
});
wss.on('connection', function(client) {
client.on('message', function(message) {
console.log('received: %s', message);
});
client.send('something');
});
// Console will print the message
console.log('-=-=- Server running :8080 -=-=-');
When I try to connect using a dead-simple client, the connection times out.
<script>
var ws = new WebSocket('ws://192.168.1.75:8080');
ws.onconnect = function(){
console.log("Connected!");
};
</script>
The server starts/runs without error, but the client always times out the connection. Do I need to configure iptables or apache to send the traffic on port 8080 to my node server that I wrote? I was thinking that the server would automatically start listening on port 8080. (I apologize in advance if this is an amature-ish question. I'm VERY new to Node.js)
You don't have to do anything special regarding Apache so long as you don't have any Apache traffic serving on the same port. You will just have two separate servers running at the same time on separate ports and will have to direct your traffic accordingly.