Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

When using node.js and socket.io, why can't I just open the client.html file instead of typing localhost in the address bar?

When using node.js and socket.io, why can't I just open the client.html file instead of typing localhost in the address bar?

Problem

I am just curious. I think it has something to do with that socket.io temporary file, but I don't really get it...

Problem courtesy of: jcora

Solution

Browsers generally don't allow HTTP requests to be made to domains different than the one the page is on. So a client.html file that's opened as a "file://..." URL in the browser can only talk to other "file://..." urls. (i.e static pages only). However socket.io requires a real webserver on the backend, so it has to be "http://..."

There are also other considerations, around how file:// urls are treated differently. (e.g. you can't set cookies, XHR requests to file:// urls don't have HTTP status codes, etc.)

Solution courtesy of: broofa

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

When using node.js and socket.io, why can't I just open the client.html file instead of typing localhost in the address bar?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×