Help with socket.io v1

383 views
Skip to first unread message

utan

unread,
Jul 19, 2013, 1:07:00 AM7/19/13
to sock...@googlegroups.com
Hi,

So I've installed socket.io v1 but I don't seem to get it to run properly can you guys tell me what I am doing wrong?

I have so far:

Server side :
 
var io         =     require('/usr/local/lib/node_modules/socket.io');// installed globally but cant find nodule

var server = new io(8080); // port as argument

server.on('connection', function(client){
    console.log('connected to socket.io v1');
    client.on('event' , function(data){
        console.log(data);
    });
});

It seems to start because I can navigate to localhost:8080

then in client side I have:


  var socket = new eio.Socket('ws://localhost:8080');
        socket.on('open', function () {
                console.log('connected');
            socket.on('message', function (data) {
           
            });
            socket.on('close', function () {
                console.log('disconnected');
            });
        });

If I use engine.io the client connects fine but not with latest socket.io..

Any suggestion ?

thanks

utan

unread,
Jul 19, 2013, 6:42:58 PM7/19/13
to sock...@googlegroups.com
No takers?

Should I wait till official release is available to start playing?

Jose Luis Rivas

unread,
Jul 19, 2013, 8:59:33 PM7/19/13
to sock...@googlegroups.com
You should not install it globally but per-project.

CD into the folder of your project and hit npm install with the packages
you want/require like:

npm install socket.io

And then require it as per documentation.

Installing modules globally is for using the binaries, not the libraries.
> --
> You received this message because you are subscribed to the Google
> Groups "Socket.IO" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to socket_io+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Jose Luis Rivas
http://eserre.com/

utan

unread,
Jul 19, 2013, 10:56:13 PM7/19/13
to sock...@googlegroups.com
I tried to do per project but when i require it the module isnt found.. so globally worked at least started..
shouldnt be the same, i thought globally would just be available to any project not to only a specific..

Jose Luis Rivas

unread,
Jul 19, 2013, 11:15:01 PM7/19/13
to sock...@googlegroups.com
On 7/19/13 7:56 PM, utan wrote:
> I tried to do per project but when i require it the module isnt found.. so globally worked at least started..
> shouldnt be the same, i thought globally would just be available to any project not to only a specific..
>
No, that's no how it works npm. npm looks for modules in the root
directory that you the file was started like
/opt/project/other/directory/file.js and then looks on
/opt/project/other/directory/node_modules, then looks at
/opt/project/other/node_modules, and /opt/project/node_modules and
/opt/node_modules and /node_modules.

It can't be found then you must be doing something bad. Running npm
install socket.io in /your/path/project should be enough. And the logic
on npm is that different projects can have different version
dependencies. It's redundant but since storage is so cheap nowadays...

And maybe your issue is that you are not making it listen on a port, you
are giving the port as argument but should be

```js
var io = require('io');
io.listen(8080);
```

Or
```js
var io = require('io').listen(8080);
```

Socket.IO website have a very straightforward example http://socket.io/

Kind regards.

--
Jose Luis Rivas
http://joseluisrivas.net/

utan

unread,
Jul 19, 2013, 11:40:36 PM7/19/13
to sock...@googlegroups.com
Yeah, but that I am using socket.io v1, the readme is no longer valid since it changing a lot go to git project and you will see the new changes..

I downloaded it using git saved in my folder project then a socket.io folder was saved then cd in the folder and install it using npm install .

Which supposedly installed it as per project , but when required didn't found the module. I then tried installing it as global npm install . -g and installed it find and could require it using full path..

I don't know if the correct procedure installing it from git.. but that's why I am posting here.


On Thursday, July 18, 2013 10:07:00 PM UTC-7, utan wrote:

Jose Luis Rivas

unread,
Jul 20, 2013, 12:09:13 AM7/20/13
to sock...@googlegroups.com
In that case:

```sh
npm install git://github.com/learnboost/socket.io.git
```

And if you want to be saved right away to your `package.json` then

```sh
npm install git://github.com/learnboost/socket.io.git --save
```

And you are missing the following line in your server before anything:

```javascript
var server = require('http').Server();
```

You are making the server an `io` object, which is not the right way.
Instead the `server` must use either the `http` library or `express`
(You could even use `connect` AFAICS). Then, the server is the one
listening to a port. So server side should be:

```js
var server = require('http').Server();
var io = require('socket.io')(server);

io.on( ... whatever ... );

server.listen(8080); // Here's where the port goes!
```

Kind regards,

On 7/19/13 8:40 PM, utan wrote:
> Yeah, but that I am using socket.io v1, the readme is no longer valid
> since it changing a lot go to git project and you will see the new
> changes..
>
> I downloaded it using git saved in my folder project then a socket.io
> folder was saved then cd in the folder and install it using npm install .
>
> Which supposedly installed it as per project , but when required didn't
> found the module. I then tried installing it as global npm install . -g
> and installed it find and could require it using full path..
>
> I don't know if the correct procedure installing it from git.. but
> that's why I am posting here.
>
> On Thursday, July 18, 2013 10:07:00 PM UTC-7, utan wrote:
>
> Hi,
>
> So I've installed socket.io <http://socket.io> v1 but I don't seem
> to get it to run properly can you guys tell me what I am doing wrong?
>
> I have so far:
>
> Server side :
>
> var io = require('/usr/local/lib/node_modules/socket.io
> <http://socket.io>');// installed globally but cant find nodule
>
> var server = new io(8080); // port as argument
>
> server.on('connection', function(client){
> console.log('connected to socket.io <http://socket.io> v1');
> client.on('event' , function(data){
> console.log(data);
> });
> });
>
> It seems to start because I can navigate to localhost:8080
>
> then in client side I have:
>
>
> var socket = new eio.Socket('ws://localhost:8080');
> socket.on('open', function () {
> console.log('connected');
> socket.on('message', function (data) {
>
> });
> socket.on('close', function () {
> console.log('disconnected');
> });
> });
>
> If I use engine.io <http://engine.io> the client connects fine but
> not with latest socket.io <http://socket.io>..
>
> Any suggestion ?
>
> thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Socket.IO" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to socket_io+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


utan

unread,
Jul 20, 2013, 12:29:02 AM7/20/13
to sock...@googlegroups.com
Great, I didn't you required a http old version would create one itself.. will try your your suggestion will get back when done..

regards.


On Thursday, July 18, 2013 10:07:00 PM UTC-7, utan wrote:

utan

unread,
Jul 20, 2013, 12:37:06 AM7/20/13
to sock...@googlegroups.com
Tried your method of installation, gave me this error Error: Invalid version: "0.1" , I will try to use the method I used to see if with the suggestion you gave me the socket.io start correctly..

utan

unread,
Jul 20, 2013, 12:53:28 AM7/20/13
to sock...@googlegroups.com
Got that error, I got so far:


var server = require('http').Server();
var io = require('/usr/local/lib/node_modules/socket.io')(server);

server.listen(8080); // Here's where the port goes!

io.on('connection', function(client){
    console.log('connected to socket.io v1');
    client.on('event' , function(data){
        console.log(data);
    });
});


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Object.<anonymous> (socket1.js:7:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

So no luck jet,  what do you think?


On Thursday, July 18, 2013 10:07:00 PM UTC-7, utan wrote:

Jose Luis Rivas

unread,
Jul 20, 2013, 12:56:33 AM7/20/13
to sock...@googlegroups.com
That means you have another service already using the port 8080. Try a
different port.
> So I've installed socket.io <http://socket.io> v1 but I don't seem
> to get it to run properly can you guys tell me what I am doing wrong?
>
> I have so far:
>
> Server side :
>
> var io = require('/usr/local/lib/node_modules/socket.io
> <http://socket.io>');// installed globally but cant find nodule
>
> var server = new io(8080); // port as argument
>
> server.on('connection', function(client){
> console.log('connected to socket.io <http://socket.io> v1');
> client.on('event' , function(data){
> console.log(data);
> });
> });
>
> It seems to start because I can navigate to localhost:8080
>
> then in client side I have:
>
>
> var socket = new eio.Socket('ws://localhost:8080');
> socket.on('open', function () {
> console.log('connected');
> socket.on('message', function (data) {
>
> });
> socket.on('close', function () {
> console.log('disconnected');
> });
> });
>
> If I use engine.io <http://engine.io> the client connects fine but
> not with latest socket.io <http://socket.io>..
>
> Any suggestion ?
>
> thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Socket.IO" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to socket_io+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Jose Luis Rivas
http://eserre.com/

utan

unread,
Jul 20, 2013, 1:06:40 AM7/20/13
to sock...@googlegroups.com
Auch, such a noob, that was it....Thanks for your kind help client side now connects...

for the record I keep it installed globally and copied the socket.io in /usr/local/lib/node_modules/socket.io to my project module folder and now I can requiere('socket.io'); as normally would...

Again my respect.. regards Jose
Reply all
Reply to author
Forward
0 new messages