<div class="post-censorship-notice">jhice can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?</div>
UPDATE : finally did not use socket.io (see Ashley's post), but use the "ws" module for node, see the post #10 below / PS Apache not needed too
Hi,
I'm running totally crazy with the Websocket and server configuration, in preview mode.
I explain :
1. Ajax plug-in
I did a test with this plug-in, just had to put the directive Header set Access-Control-Allow-Origin "http://localhost:50000" and it ran well. Put it where the ajax.php file resides. NO PROBLEM, half an hour to test it from scratch.
2. Websocket plug-in
I did want to try it from scratch with no knowledge of node.js. I installed node.js and socket.io, no problem at this point. After that I wanted to try the official C2 WS plug-in in the same way I did with the Ajax one. It doesnt worked at first try, the server was not tracing any connection from the client (C2 preview). "Anyway" I thought, it is rare that it works at first try !
So I took a look at the examples on the socket.io page. First, they didn't tell that we must include the js src from the socket server port (1337 here ^^), ie : <script src="http://localhost:1337/socket.io/socket.io.js"></script>. This was solved anyway.
The nightmare started here, I couldnt get rid of the following error after 2 hours (if not 3) :
XMLHttpRequest cannot load localhost/socket.io/1 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
The directive in the .htaccess, even wth the wildcard "*", didn't seemed to do the trick this time (because now there are 2 servers and not only 1, as in the Ajax example). I went on stackoverflow and to the site about "CORS" : enable-cors.org/server_apache.html but didnt manage to solve the problem.
In my app.js I've got something like this, but the "origins" key doesnt do the trick either :
var io = require("socket.io").listen(1337);
io.set('origins', '*');
To say, the socket.io documentation is not very clear...
So, I dont get where to put the Header directive, in Apache .htaccess, that serve the client socket (.html or C2 preview), or in the app.js server run by node/socket.io. I didn't try to use only the built-in server of node (Express) and not Apache, because I dont want to, and I think the localhost:50000 of C2 will run in the same issue than Apache.
If someone could help on this, I would be grateful !
Thanks
PS : I wanted to try by myself from scratch with the C2 Websocket plug-in before going in rexrainbow plug-in or in the tutorial by SgtConti.