socket.io - ReferenceError: io is not defined

socket.io cdn
socket = io client
get http://localhost:3000/socket.io/socket.io.js net::err_aborted 404 (not found)
io is not defined python
socket io tutorial
referenceerror io is not defined learn more
socket io java
socket io basics

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 server (which uses the Twisted engine to retrieve the data).

I've tried many things and looked at various forums, answers, tutorials, and web pages--including most of them here--and can't find an answer. Here's the relevant Javascript I have in my index.html file:

<script src="socket-lib/socket.io.js"></script>
<script type="text/javascript" charset="utf-8">
function sendData() {
    try {
        var socket = io.connect('http://mywebsite.com:12345');
        socket.on('connect', function(data) {
            socket.send('Hello.');
            socket.on('message', function (msg) {
                socket.send('This is where I send data?');
            });
        });
    }
    catch(err) {
        alert('ERROR: socket.io encountered a problem:\n\n' + err);
    }
} // end of sendData

If you can't tell, I'm still pretty confused how this works; I can't even test anything. The error that keeps coming up is ReferenceError: io is not defined. Some sites used something like var io = require('socket.io');. But then it results in the same error: ReferenceError: require is not defined.

I put the socket-lib folder in assets/www, where any other Javascript source should go. This is also where the index.html file is. Many sites use <script src="/socket.io/socket.io.js"></script>, but this makes no sense to me. Many sites also imply the use of node.js, but I never see it anywhere.

How can I make this work?

Reply edits:

I tried it in Chrome, and it's giving me an Uncaught ReferenceError: require is not defined for the socket.io.js file. So I decide to source in require.js right before it. Then it gives the error Uncaught Error: Module name "socket.io-client" has not been loaded yet for context. Since I'm not using this, I care not. When I try the connection, though, it gives the same io is not defined error. When I define it as var io = require('socket.io'), the error is Error: Module name "socket.io" has not been loaded yet for context: _ http://requirejs.org/docs/errors.html#notloaded. I looked at the website, and it doesn't help me at all. When I try to put "require" as a function argument, another error occurs: TypeError: undefined is not a function.

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.

Step.9 Uncaught ReferenceError: io is not defined at main.js:45 , import VueEcho from 'vue-echo'; Vue.use(VueEcho, { broadcaster: 'socket.io', host: 'http://site.local:6001' }); Error: Uncaught ReferenceError: io  I tried it in Chrome, and it’s giving me an Uncaught ReferenceError: require is not defined for the socket.io.js file. So I decide to source in require.js right before it. So I decide to source in require.js right before it.

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

Uncaught ReferenceError: io is not defined · Issue #5 · happyDemon , ReferenceError: io is not defined C:/Users/Shmulik/IdeaProjects/ch-12/public/​index.html:55". The code at this lie is: "socket = io.connect(');". This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet.

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.

Uncaught ReferenceError: io is not defined – IDEs Support (IntelliJ , Include the socket.io javascript on the client side --> <script> Uncaught ReferenceError: io is not defined dev.nodejs.putoshop.com/:14 > I'm trying to get socket.io working but now in Chrome I get the error: Uncaught ReferenceError: require is not defined client.php:9Uncaught ReferenceError: io is not defined I changed the way to

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

hope this will solve your problem

io is not defined, js (linje 1) ReferenceError: io is not defined var socket = io.connect('http://192.168​.0.105:8888');. Here is the server script. var io = require('socket. I'm having trouble debugging javascript project.I'm trying to debug both server and client side locally at the same time.I'm using Node, Express, and socket.io.The main.js under the server runs OK

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.

Socket.io - Cannot load file or io is not defined, Uncaught ReferenceError: io is not defined in socket.io application - node.js. Questions: I’m trying to get socket.io working but now in Chrome I get the error: Uncaught ReferenceError: require is not defined client.php:9Uncaught ReferenceError: io is not defined I changed the way to include the socket.io.js file because it dosnt exists somewher else: If I try I get: Failed to load resource:

Uncaught ReferenceError: io is not defined in socket.io application , But the instructions are telling me not to define io in that file but just to write ReferenceError: io is not defined” … perhaps the javascript engine in it's because io literally isn't defined: when you do var socket = io(); , io  You can also tell JSHint that io is a global variable. it recognizes this comment notation and won't bother warning you that io isn't being defined in your service (which it doesn't need to be since it's global) just put this before your module declaration at the top of your factory service

Advanced Node and Express, createServer(app), io = require('socket.io').listen(server), logger = require('​winston'), port ERROR Uncaught ReferenceError: io is not defined. In any case, this issue should not be resolved IMO, socket.io-client should either remove the implicit dependency on global, or document that a polyfill is needed (by anyone using the pre-bundled sources, not just Angular users)

Socket.io and Laravel cant connect to socket, connect I get the following error: Uncaught ReferenceError: io is not defined at f (inspector.js:1) There may be scoping issue with socketio. Maxwell2022 changed the title Loading socket.io client from CDN trigger "io is not defined" Loading socket.io client from CDN triggers "io is not defined" May 30, 2014 This comment has been minimized.

Comments
  • 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 "yourwebsite.com:12345/socket.io/socket.io.js". The server automagically does the rest for you.
  • you are my new favorite person sir! Their samples on socket.io are horribly misleading.
  • According the documentation, since v1.0 you can request the client library from their CDN: socket.io/blog/introducing-socket-io-1-0/#cdn-delivery
  • And the port (12345) mentioned here is nothing but the port on which node is running with socket.io
  • I had forgot to create VirtualHost in /etc/apache2/httpd.conf to point the port where my node server was running, in my case it was <VirtualHost *:8000>...
  • I was getting this error because of line this: <script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js"></script> was looking like nonsense, cause when I use in fresh html file - it was working, but then tried by parts - use php die() and start from beginning of the file - it was working until I my sockets script went after require.js lib. Eearlier it did not do any harm but maybe when node udpated something - it broke.
  • Why? This is a client side library, so why does it need to be loaded from the server which you are trying to connect to? Connection params are in the connect method.
  • I opened a new directory, installed dependencies and it worked! Sometimes, it's just a bad installation...maybe a broken dependency (or permissions).
  • Because of the folder structure of the installed socket.io package. It must point the to the root server folder then to the socket.io path
  • Do you have any other advice? I still can't get this to work.
  • Without actually seeing both your code and your directory structure, it's pretty hard to tell what is wrong. Maybe you could upload your progress so far somewhere?
  • All the code that is relevant is already posted. The problem persists when all other Javascript is taken away. As for the directory structure, it's in Eclipse SDK, and the project is HelloWorld. The file "index.html" and the folder "socket-lib" are both in "HelloWorld/assets/www". The only other important file (I think) would be the Java file: "HelloWorld/src/com.helloworld.helloworld/Hello.java". It was created by default; the only thing I did there was changing the setContentView() line to super.loadUrl("file:///android_asset/www/index.html");.