title: socket.io-client connecting, but not emitting
body: <p>I am making a little encrypted chat app, in the terminal, using socket.io-client and socket.io. The client is able to connect to the server, but is not emitting the username, when its entered. </p>
  
  <p>Client: </p>
  
  <pre><code> var socket = require('socket.io-client')('http://127.0.0.1:3000');
   socket.on('connect_error', function(){
  console.log('Failed to establish a connection to the servers, or lost     connection');
  
   return process.exit();     
    });
   var prompt = require("prompt-sync")()
   var news = "Add news: Will be from database. " 
   var username = prompt("Username&gt;: ")
  
   console.log("Hold on a sec, just checking that!")
   console.log("")
   if (typeof username === "defined"){
   socket.emit('user-name', {usr: 'username'})
   }
  
  
  socket.on('user-name-good',function(socket){
  console.log("Okay! Your username looks good, we just require your password")
  console.log("If you chose to have no password, please press enter with    out pressing space!")
   var password = prompt("Password&gt;: ")
    if (typeof password !== "defined"){
      console.log("Please provide a password!")
      return password = prompt("Username&gt;: ")
   }
  
   socket.on('user-name-fail',function(socket){
   console.log("Sorry, we could not find, "+username+""+"Please register    on the website, or, if you have registered ")
   return process.exit()
  })    
  
  }
  )
  </code></pre>
  
  <p>Server code, is based on code from socket.io chat example: </p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
  });
  
  io.on('connection', function(socket){
  socket.on('chat message', function(msg){
  io.emit('chat message', msg);
  });
  });
  
  http.listen(3000, function(){
  console.log('listening on *:3000');
  });
  </code></pre>
  
  <p>I have added a error event, this closes the client if a connection to the server fails, so I know its connecting, any help appreciated, I have done research on this topic, and tried a lot of other methods, but to no avail.</p>
  
  <p>Also the connection is made after you submit data, not when the client code is started, what could be causing this? </p>