How to connect to a remote Node.js server?

I'm using C9.io

Here my server:

var io = require('socket.io');


  var socket = io.listen(8080, { /* options */ });
  socket.set('log level', 1);


  socket.on('connection', function(socket) {

        console.log("connected");

    socket.on('message1', function(data) {
          socket.emit("message1",JSON.stringify({type:'type1',message: 'messageContent'}));

    });

    socket.on('disconnect', function() {

         console.log("diconnected");

    });
  });

When i run it generate this url: https://xxx-c9-smartytwiti.c9.io and tell me that my code is running in this URL.

Note: xxx is my workspace

What i did in my client: Connect to "https://xxx-c9-smartytwiti.c9.io:8080/" ....

Then i get this error on console(firefox browser):

cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xxx-c9-smartytwiti.c9.io:8080/socket.io/1/?t=1406060495041. This can be fixed by moving the resource to the same domain or enabling CORS.

Note: when i host my server locally it works perfectly.

Seems like c9.io using a proxy or a firewall, but how can i test my code written in the c9.io remotely ?

UPDATE

According to ruben's response i've changed my server, and it works when my socket.io-client hosted in C9 but still can't get this working on remote client(i've also hosted the client in my FTP but same result):

// module dependencies
var http = require("http"),
    sio  = require("socket.io");

// create http server
var server = http.createServer().listen(process.env.PORT, process.env.IP),

// create socket server
io = sio.listen(server);

// set socket.io debugging
io.set('log level', 1);


io.set('origins', '*:*');


io.sockets.on('connection', function (socket) {


  socket.emit('news', { message: 'Hello world!' });

  socket.on('my other event', function (data) {
    console.log(data.message);
  });

});

Looks like the origin configuration has been ignored, i'm also not sure about C9.io..

suggestions ?

Cheers.

You are using port 8080. Instead try using process.env.IP and process.env.PORT. In addition it is important to not specify a port on the domain to your workspace. The default port (port 80) is forward to the internal port of your container on c9.io. If you connect to the default port by not specifying it you won't have a problem with cross domain security.

See also: https://c9.io/site/blog/2013/05/native-websockets-support/

Ruben - Cloud9 Support

Same-origin policy requires that your client code and WebSocket server be hosted at the same URL and port. You can find specific examples of ways to integrate them in the Socket.IO docs. Here's their example of how to do it using the built-in HTTP server. Instead of giving Socket.IO a hostname/port, you give it your webserver object:

var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(80);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});