using socket.io with cordova and IOS device

前端 未结 2 2018
無奈伤痛
無奈伤痛 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);
                });
            });
        });
    
    0 讨论(0)
  • 2021-01-01 05:21
    <script src="http://localhost:3000/socket.io/socket.io.js"></script>
    var socketHost = "http://localhost:3000";
    var socket = io.connect(socketHost);
    
    0 讨论(0)
提交回复
热议问题