Rectangle 27 11

app.listen(8080);
server.listen(8080);

You are awesome man....and may i know the reason behind it?

javascript - Uncaught ReferenceError: io is not defined - Stack Overfl...

javascript node.js express socket.io
Rectangle 27 5

The reason that javascript is sometimes labeled as a non-blocking IO is because of the concept of anonymously defined, (event based), functions. Node.js specifically labels this as their reasoning why javascript is a good server side language. This however, is only a half truth, as it is not technically non-blocking, but it will continue to execute code while waiting for a callback from an anonymous callback/ajax function. I'm not sure if this is what you read, but an explanation offered in one Node tutorial is:

"The other method, the one taken by Node and some extremely fast modern servers such as Nginx and Thin, is to use a single non-blocking thread with an event loop. This is where the decision to use JavaScript really shines, since JavaScript was designed to be used in a single threaded event loop-based environment: the browser. JavaScripts ability to pass around closures makes event-based programming dead simple. You basically just call a function to perform some type of I/O and pass it a callback function and JavaScript automatically creates a closure, making sure that the correct state is preserved even after the calling function has long since gone out of scope."

In reference to your multithreading tag, Node.js and Javascript are NOT multithreaded, they use a system of closures to preserve state while waiting for a callback. Therefore, they are NOT completely non-blocking. There are plenty of scenarios where blocking can occur, but for most small implementations, a developer will never encounter a blocking situation.

both the cancer link and the non-cancer link are dead to me

Sorry about that. I would try googling the article titles and see if they are archived somewhere. Those links are private blogs, so I think its safe to assume they would migrate after 3 years.

also, Node.js is multithreaded - all the i/o calls happen on a different thread than the main event loop thread

Can you source that assertion? Because Node.js is Javascript, it is by nature single threaded.

nonblocking - How does non blocking IO work in javascript - Stack Over...

javascript nonblocking
Rectangle 27 0

app.listen(8080);
server.listen(8080);

javascript - Uncaught ReferenceError: io is not defined - Stack Overfl...

javascript node.js express socket.io
Rectangle 27 0

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

/socket-lib/socket.io.js;

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.

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror
Rectangle 27 0

Your node.js application still has to serve it - it does not get served automagically. What do you have in your server? It should be something like

var app = require('express').createServer();                                    
var io = require('socket.io').listen(app);

or similar (the listen is important). The location is not a real location on the disk - socket.io library should intercept the URL and serve its clientside library, as far as I understand.

I have both of those lines already, but thanks

javascript - Node.js socket.io.js not found or io not defined - Stack ...

javascript html node.js socket.io
Rectangle 27 0

Add the following after body parser:

, express.static(__dirname + "/public")
var app = module.exports = express.createServer(
  express.bodyParser()
  , express.static(__dirname + "/public")
);

javascript - Node.js socket.io.js not found or io not defined - Stack ...

javascript html node.js socket.io
Rectangle 27 0

Try creating another node.js application that has this single line in it and then run it with node.js

var io = require('socket.io').listen(8000);

Then in your browser visit http://127.0.0.1:8000 and you should get the friendly "Welcome to socket.io." greeting. If you are getting this then socket.io is running and will serve the socket.io.js file.

The only other thing that I can think of that might be happening is that you might not be linking to the alternate port in your client file. Unless you're running the socket.io server on express which is running on port 80. For now create a client file that has the script source for socket.io set to

<script src="http://127.0.0.1:8000/socket.io/socket.io.js"> </script>

This should connect to the socket.io server running on port 8000 and get the socket.io.js file.

Thanks, this didn't happen, I'll see about fixing it.

I'm so confused. I am having the same problem, and this does work, tho I definitely want to fix it without running a separate server. "The only other thing that I can think of that might be happening is that you might not be linking to the alternate port in your client file" What do you mean by that, I'm using express on port 3200, is there anything special I have to do with socket.io for it to server the client js file on port 3200?

javascript - Node.js socket.io.js not found or io not defined - Stack ...

javascript html node.js socket.io
Rectangle 27 0

The reason that javascript is sometimes labeled as a non-blocking IO is because of the concept of anonymously defined, (event based), functions. Node.js specifically labels this as their reasoning why javascript is a good server side language. This however, is only a half truth, as it is not technically non-blocking, but it will continue to execute code while waiting for a callback from an anonymous callback/ajax function. I'm not sure if this is what you read, but an explanation offered in one Node tutorial is:

"The other method, the one taken by Node and some extremely fast modern servers such as Nginx and Thin, is to use a single non-blocking thread with an event loop. This is where the decision to use JavaScript really shines, since JavaScript was designed to be used in a single threaded event loop-based environment: the browser. JavaScripts ability to pass around closures makes event-based programming dead simple. You basically just call a function to perform some type of I/O and pass it a callback function and JavaScript automatically creates a closure, making sure that the correct state is preserved even after the calling function has long since gone out of scope."

In reference to your multithreading tag, Node.js and Javascript are NOT multithreaded, they use a system of closures to preserve state while waiting for a callback. Therefore, they are NOT completely non-blocking. There are plenty of scenarios where blocking can occur, but for most small implementations, a developer will never encounter a blocking situation.

nonblocking - How does non blocking IO work in javascript - Stack Over...

javascript nonblocking
Rectangle 27 0

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>

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror
Rectangle 27 0

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.

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");.

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror
Rectangle 27 0

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:

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

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror
Rectangle 27 0

this

try writing them in separate lines.

var io = require('socket.io');
io.listen(PORT);

It is alray in, not? io = require('socket.io').listen(PORT); If I try your solution this give me: This returns me ' Cannot call method 'on' of undefined when I run node server.js

sorry, you mean the client side? please check if your client loaded socket.io/socket.io.js correctly. io should be defined there.

client side I have: <script src="78:233:79:103:8000/socket.io/socket.io.js" /> (and if I want it to work with local node server I change it in <script src="localhost:8000/socket.io/socket.io.js />)

javascript - Node.js on a remote server: io is not defined - Stack Ove...

javascript node.js socket.io
Rectangle 27 0

<script>src="http://localhost:8080/socket.io/socket.io.js"</script>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>

javascript - node.js Socket io "Reference error io is not defined" - S...

javascript html5 node.js mongodb socket.io
Rectangle 27 0

I managed to blunder through this, and squandered about an hour, on something that turned out to be a very basic error.

When an function is not defined? Such as " Uncaught ReferenceError: io is not defined ". Does that not mean that the function is getting "used" before it is "created"?

In the part of my HTML file, that "calls" the javaScript files, it looked like this :

<script src='./js/playerChatter.js'></script> <!-- this one calls io -->
<script src="http://localhost:2019/socket.io/socket.io.js"></script><!-- This Creates io -->
<script src="http://localhost:2019/socket.io/socket.io.js"></script> <!-- This Creates  io -->
<script src='./js/playerChatter.js'></script> <!-- this on calls io -->

So now the item "io", whether it is an object or function... Is actually getting created before it is getting used :D

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror
Rectangle 27 0

For me after debugging through all of the very helpful suggestions, it turned out to be simply that my node server had stopped. I had been running it manually in a terminal window during dev.

Make sure your node [yourservercode].js is running on the specified port! :-]

javascript - socket.io - ReferenceError: io is not defined - Stack Ove...

javascript android ios socket.io referenceerror