Question

Hi I am trying to use Engine.IO. As stated here on StackOverflow it is supposed to be low level version of Socket.IO. Also it supposed to be better and newer. Also it should give me the ability to easily exchange messages between browser client and Node.js server. Doh.

I read from top to bottom these two pages:

https://github.com/LearnBoost/engine.io

https://github.com/learnboost/engine.io-client

But it does not help, those manuals seem to be written for somebody who already know how to use the technology not for somebody who is trying to learn it. Even the basic parts are missing.

How the client script is supposed to get to the browser?

What is the landing address for the "hello world" I should type in the browser?

Step-by step instruction to got started?

Please help! This is not easy when you try to learn something like that!

This is what the client script supposed to be:

<script src="/path/to/engine.io.js"></script>
<script>
  var socket = new eio.Socket('ws://localhost/');
  socket.on('open', function () {
    socket.on('message', function (data) { });
    socket.on('close', function () { });
  });
</script>

But now what is that? Index.html? What does it all mean? How to use it?

Now here is the "server" part:

(A) Listening on a port

var engine = require('engine.io')
  , server = engine.listen(80)

server.on('connection', function (socket) {
  socket.send('utf 8 string');
});
(B) Intercepting requests for a http.Server

var engine = require('engine.io')
  , http = require('http').createServer().listen(3000)
  , server = engine.attach(http)

server.on('connection', function (socket) {
  socket.on('message', function () { });
  socket.on('close', function () { });
});
(C) Passing in requests

var engine = require('engine.io')
  , server = new engine.Server()

server.on('connection', function (socket) {
  socket.send('hi');
});

// …
httpServer.on('upgrade', function (req, socket, head) {
  server.handleUpgrade(req, socket, head);
});
httpServer.on('request', function (req, res) {
  server.handleRequest(req, res);
});

Why is this broken in three parts? Which one corresponds to the client example? Maybe I sound dumb, but how to get the "hello world" going?

Was it helpful?

Solution

I would suggest you read the following book , it will clear out some of your concerns. "http://www.nodebeginner.org/".

Then try to make your first NodeJS App just doing what the book says , so that you get a bit the idea behind it.

After that go on and use "socket.io" and create a simple app with the help of this tutorial "http://net.tutsplus.com/tutorials/javascript-ajax/real-time-chat-with-nodejs-socket-io-and-expressjs/".

After that i believe you will not have any questions regarding engine.io and you will be able to go on with your project. Jumping to engine.io without prior knowledge of "NodeJS" and "socket.io" has a hard learning curve.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top