0

Am I doing something wrong? When I run node client.js. I am getting this error message:

/web/ws/node_modules/socket.io/node_modules/engine.io/lib/server.js:358
  var listeners = server.listeners('request').slice(0);
                         ^
TypeError: Object http://localhost:8080 has no method 'listeners'
    at Server.attach (/web/ws/node_modules/socket.io/node_modules/engine.io/lib/server.js:358:26)
    at Function.attach (/web/ws/node_modules/socket.io/node_modules/engine.io/lib/engine.io.js:124:10)
    at Server.listen.Server.attach (/web/ws/node_modules/socket.io/lib/index.js:226:21)
    at new Server (/web/ws/node_modules/socket.io/lib/index.js:51:17)
    at Server (/web/ws/node_modules/socket.io/lib/index.js:39:41)
    at Object.<anonymous> (/web/ws/client.js:2:14)
    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)

Here is my code:

var io = require('socket.io');
var socket = io('ws://localhost:8080');
  socket.on('connect', function () {
    socket.send('hi');
    socket.on('message', function (msg) {
      // my msg
    });
  });

Please suggest something. where I am doing the mistake ?

4
  • Did you try just var socket = io();, without the adress ? Commented Mar 17, 2015 at 13:11
  • no.. let me try. I'll let u know Commented Mar 17, 2015 at 13:12
  • After calling node client.js I am getting nothing. Even not getting any error Commented Mar 17, 2015 at 13:14
  • Use socket.io-client package Commented Mar 17, 2015 at 13:31

1 Answer 1

4

The problem here is that you are trying to use socket.io package which is for configuring the server.

Instead you need to use socket.io-client package to be able to act as a client.

You can find usage examples by following provided links.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.