using socket.io with cordova and IOS device

前端 未结 2 2052
無奈伤痛
無奈伤痛 2021-01-01 04:46

I\'m trying to use this simple tutorial:

http://socket.io/socket-io-with-apache-cordova/

My node.js is working fine and i\'m emulating to i

2条回答
  •  温柔的废话
    2021-01-01 05:17

    I made it, this tutorial is very good but it's not totally right.

    You have to connect the socket to your server first (i'm using localhost and port 3000, but if you're using some server outside, i think you've to just put the ip and port):

    var socket = io.connect('http://localhost:3000');
    

    and after that, you call "socket.io", here is my complete code:

    document.addEventListener('deviceready', function() {
            var socket = io.connect('http://localhost:3000');
            socket.on('connect', function() {
                socket.on('text', function(text) {
                    alert(text);
                });
            });
        });
    

提交回复
热议问题