Reputation: 533
My nodeJS code isn't working for some reason. I'm new to nodeJS, so excuse my ignorance. Here's the server code:
var http = require('http');
console.log("before");
var app = http.createServer(function (request, response) {
console.log("Server Created");
}).listen(3000);
var io = require('socket.io').listen(app);
io.sockets.on('connection', function(socket) {
console.log("Client Connected");
});
Here is my client code:
<script type="text/javascript">
var socketio = io.connect("http://localhost:3000");
</script>
I run the server, then go to index.html which contains the client code. I feel like I must be missing something obvious :| Client Connected never prints.
Upvotes: 0
Views: 80
Reputation: 569
looks like your server code is just fine.
Have you tried changing localhost to IP Address in your client code like the following:
...
<script type="text/javascript" src="http://<YOUR_IP>:3000/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io('http://<YOUR_IP:3000');
</script>
Upvotes: 1