I am trying to create a simple chat application using Node js. I am using a windows operating system. As local server I am using Xampp. I have installed node. I have also installed
socket.io using package.json. The code in package.json is given below.
{
"name":"chat",
"version":"0.0.1",
"private":"true",
"dependencies":{
"express":"3.4.0"
}
}
Then I have written the code for the server. The node server is running in port 1337. The code for the server is given below.
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Then when I run it, it is running. Then I have written the code for the client in a index.php file. The code for the client is given below.
<!DOCTYPE html>
<html>
<head>
<title>Chat app.</title>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
var socket = io.connect('http: // localhost / node : 1337');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
});
</script>
</body>
</html>
But when I try to the run it with a browser, all I get see in the console is that access is forbidden. BTW, if it is important all my files including node_modules is saved in C:\xampp\htdocs\node. Please help me. I am stuck for quite some days. Thanks in advance.