get socket-io plugin 2 work with socket.io on node

Get help using Construct 2

Post » Mon Jul 22, 2013 3:00 pm

I have a tiny test app running on node.js with socket.io installed:

var io = require("socket.io").listen(8080);
io.sockets.on('connection', function (socket) {
    console.log("connected");
    socket.emit('balls', { ball:42 });
    socket.on('daub', function (data) {
      console.log(data);
    });
});


As you can see, it sends one message, and logs when it receives one.

I know its all working as when I try this test js outside of C2, it works:

<html>
<head>
</head>
<body>
<script src="socket-io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8080');
socket.on('balls', function (data) {
    console.log(data);
    socket.emit('daub', { my: 'data' });
});
</script>
</body>
</html>

Using the official C2 web sockets plugin, nothing happens.

Using Zacks socket.io plugin: http://www.scirra.com/forum/plugin-zack0wack0s-socketio-mod_topic56503.html

Nothing happens.

My capx simply says:

system->On load complete=WebSocket connect to "ws://localhost:8080" (required protocol "").

It never connects to the server. no errors no nothing.

WebSocket->On message is never fired.
WebSocket->On connection error is never fired.
WebSocket->On connection opened is never fired.

The same using the Socket object provided by Zacks plugin, it does nothing. i.e.

system->On load complete=Socket Connect to "ws://localhost" (port 8080 specified in the dialogue) never connects. It also never calls any events, such as On Connect or on error.

They are both just "dead". But I know the server side is working fine.

any ideas?
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Mon Jul 22, 2013 7:43 pm

ws://localhost ?
try: localhost
"It's done when it's done"

Shadows of War
Buy on Steam ;)
B
23
S
10
G
7
Posts: 253
Reputation: 4,896

Post » Mon Jul 22, 2013 10:45 pm

Ok, got it to connect now, but no joy on transferring messages in either direction. Neither side sees the messages from the other. I am guessing its because node.js uses two parameters, and the web socket implentation only uses one. I.e. the "balls" and "daub" in my example. Unfortunately, the official web socket manual page has no examples or info on what it expects on the server side, and i cant find a server side web socket implementation which is compatible with it.

I think my only option here is to develop my own plugin, as my client and server javascript works fine, its just the 3 or 4 existing web socket and socket.io plugins for C2 dont work with node.js and socket.io.

I chose node.js and socket.io for speed of prototyping and compatibility, but will probably switch to smartfoxserver 2x, kaazing or jwebsocket for production.nutmix2013-07-22 22:49:41
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Tue Jul 23, 2013 12:08 am

OK, being new to web sockets, and socket.io (but have been programming unix sockets for 30 years), i realise where i was going wrong.

Socket.io is not compatible with web sockets.

I installed the ws package on node.js, and changed the server side test program to this:

var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
    ws.on('message', function(message) {
        console.log('received: %s', message);
    });
    ws.send('something');
});

And it works with the C2 web sockets.

However, web sockets suck compared with the features of socket.io and jwebsockets, so I will be developing plugins for one of those. (could not get Zacks socket.io to work).
B
17
S
6
G
3
Posts: 370
Reputation: 3,942


Return to How do I....?

Who is online

Users browsing this forum: BlueGuy3, ColombageEnPLS, FlyingRam, plinkie, Yahoo [Bot] and 3 guests