Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The problem I faced was, serving the client socket.io.js from a different location.
- You can avoid this issue by serving the client js file from the same server where you are trying to connect to.
- for example, my initial client code was this and it was throwing error
- <script src="/socket.io/socket.io.js"></script>
- var socket = io.connect('http://mydomain.com/');
- -----
- once I modified it to this, it worked alright.
- -----
- <script src="http://mydomain.com/socket.io/socket.io.js"></script>
- var socket = io.connect('http://mydomain.com/');
- -----
- And my server code is,
- -----
- var express = require('express');
- var app = express();
- app.use(function(req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "X-Requested-With");
- res.header("Access-Control-Allow-Headers", "Content-Type");
- res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
- next();
- });
- var server = http.createServer(app);
- io = socketio.listen(server, {log:false, origins:'*:*'});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement