I installed Node on my Windows server using the .msi package that can be downloaded at the nodejs.org website, and it's running fine. Then I ran npm install socket.io and that went fine, too. It installed socket.io to C:\node_modules\socket.io. I added the example server code found on the socket.io website into a new file called app.js. The only change I made was the port number to 1337. I then started Node with app.js like so: node app.js into the command line, and got the info: socket.io started message.
On the clientside--my OSX laptop where I'm developing my web app--I'm not sure how to properly get the socket.io.js file and all its dependencies so I can include it in my HTML page's <script> tag. From the How do I serve the client FAQ page on the socket.io Wiki:
The client is served automatically by the Node.JS server. In your tag of your HTML, include:
<script src="http://<uri:port>/socket.io/socket.io.js"></script>
So, I added this to my index.html page:
<script src="http://my.windows.server.domain.com:1337/socket.io/socket.io.js"></script>
When I upload my index.html file to my webserver, and point my browser to it, I check the console and find:
XMLHttpRequest cannot load http://localhost/socket.io/1/?t=1330983853883. Origin http://my.web.server.domain.com is not allowed by Access-Control-Allow-Origin.`
Has anybody encountered this message with socket.io? Any tips as to how I can get the client to include the code it needs so I can begin using the awesomeness that socket.io is?
This is because normally XHR cannot be cross-domain (and the initial "handshake" goes through XHR before raising to socket.io protocol). Did you do something with default socket.io settings? Try adding this:
io.set("origins","*");
in your socket.io server settings. If this does not work, then maybe you use old version of socket.io? I think 0.9 is current.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With