access is forbidden for socket.io.js

790 views
Skip to first unread message

Shamir Khandaker

unread,
Sep 25, 2013, 5:30:35 PM9/25/13
to nod...@googlegroups.com
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":{
    "socket.io":"0.9.16",
    "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.

    var io = require('socket.io').listen(1337);
    
    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 src="/node:1337/socket.io/socket.io.js"></script>
    <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.

Angel Java Lopez

unread,
Sep 25, 2013, 5:57:45 PM9/25/13
to nod...@googlegroups.com
Ummm... Reading your email, I guess you don't have exposed /node via localhost

Your socket.io server could be accessed via


Try


and you should get a javascript text

Then, alter your HTML from
<script src="/node:1337/socket.io/socket.io.js"></script>
to

It works?

Angel "Java" Lopez
@ajlopez


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages