1

I am able to connect a web based app to a socket.io server, but not a terminal based app, this is what i use to connect to the socket.io server:

var socket = require('socket.io')
var connection = socket.connect('http://127.0.0.1:8080');   

I get the following error:

 TypeError: socket.connect is not a function

How can I connect a terminal app to a socket.io server, written in node.js

4
  • why are you using socket before importing it? Commented Apr 22, 2016 at 21:04
  • I've tried it both ways round: Commented Apr 22, 2016 at 21:05
  • 1
    Try the browser client? Commented Apr 22, 2016 at 21:07
  • I do not want to use a browser, its a terminal based application I wan't to connect to my socket.io server Commented Apr 22, 2016 at 21:08

1 Answer 1

2

The socket.io is for creating WebSocket server. You can't use this module as a client. Instead try socket.io-client

  var socket = require('socket.io-client')('http://127.0.0.1:8080');
  socket.on('connect', function(){});
  socket.on('event', function(data){});
  socket.on('disconnect', function(){});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.