socket.io - ReferenceError: io is not defined

后端 未结 8 1570
再見小時候
再見小時候 2020-12-02 13:11

I am writing an application for Android 2.3.5 (that will also be compatible with iOS). I wish to transfer data from the app\'s HTML/Javascript to a Python program on a serve

相关标签:
8条回答
  • 2020-12-02 13:44

    I found the answer for anyone who gets immensely confused by the horrible lack of documentation of socket.io.

    You cannot source /socket-lib/socket.io.js,

    you must source http://yourwebsite.com:12345/socket.io/socket.io.js.

    The server automatically does the rest for you.

    0 讨论(0)
  • 2020-12-02 13:49

    write server side code in socket.io.js file and try src="/socket.io/socket.io.js"

    hope this will solve your problem

    0 讨论(0)
  • 2020-12-02 13:49

    I use jspm.

    Add this:

    import 'btford/angular-socket-io/mock/socket-io';
    
    0 讨论(0)
  • 2020-12-02 13:53

    I solved it myself by changing index.html to import the socket io client from bower, first i installed the bower component:

     bower install socket.io-client
    

    then i changed the reference in index.html to :

     <script src="bower_components/socket.io-client/socket.io.js"></script>
    

    Or file could be found at - lib/socket.io-client/dist/socket.io.js

    0 讨论(0)
  • 2020-12-02 13:55

    When getting socket.io to work with many other libraries using require.js I had same error, it turned out to be caused because of trying to load the socket.io.js file from the same /js folder than the rest of the other files.

    Placing it in a separated folder, fixed it for me, you can see the code in this gist but all I changed for making it work, was this:

    instead of:

    socketio: 'socket.io',

    Use:

    socketio: '../socket.io/socket.io',

    Not sure about the reason of this behavior, but I hope it helps you.

    0 讨论(0)
  • 2020-12-02 13:56

    This looks like your browser cannot find the socket.io.js file. You could try opening the index.html on your computer with Firefox+Firebug or the Chrome Web Developer Tools and look at how the .js file is requested. On the other side, you could check the logs on the webserver serving the .js file whether there are any file not found errors.

    The require function would be provided by e.g. RequireJS, but you would still need to configure the paths to your scripts correctly for it to work.

    0 讨论(0)
提交回复
热议问题