 
       else
         if message.reply_to
-          if message.ok
+          if message.type == 'pong'
+            @_lastPong = Date.now()
+            delete @_pending[message.reply_to]
+          else if message.ok
             console.log "Message "+message.reply_to+" was sent"
             if @_pending[message.reply_to]
               m = @_pending[message.reply_to]

        @emit 'open'
        @connected = true

      @ws.on 'message', (data, flags) =>
        # flags.binary will be set if a binary data is received
        # flags.masked will be set if the data was masked

    if not @connected
      return false
    else
      if @_pongTimeout
        clearInterval @_pongTimeout
        @_pongTimeout = null

      # We don't set any flags or anything here, since the event handling on the socket will do it
      @ws.close()
      return true
