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

0 favourites
  • 4 posts
From the Asset Store
Node Downloader is a plugin for download file for Construct 3 and construct 2 game engine
  • 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: 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?

  • ws://localhost ?

    try: localhost

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)